Say I have the below xml string :
<root>
<a>
<c> </c>
</a>
<b> </b>
</root>
Say i want immediate children of 'root' my approach :
Extract tags inside root by using regex:
extractedString = myXmlString.match(/<(\w+)([^>])>([\s\S])</\1>/g)[3]
use a regex to get the child tags , but it gives me all the children i use this regex on the extracted string (i.e. the string between the root tags)
childArray = extractedString.match(/<\w+/g)
but the above one also returns me c which is obvious , is there any way of extracting only a and b . or is this approach wrong? I am not looking forward to use any library please do correct me if my approach is wrong towards this (i.e. using regex) and suggest the correct way of doing this.