Supposing you get an XML string that looks like this

instead of this.

Since the tag “name” is not enclosed within another tag, you can use the Document object’s getElementsByTagName() method to get all tag nodes that match the tag name. Since we are only interested in one tag, we can quit the loop after getting the first node of the NodeList object.

Once you get the Node object, you can then use the code below to extract the value of the tag where node is the variable of the node object that the method above returns.

Related Posts Plugin for WordPress, Blogger...