Following is my xml from where I have to get attribute value:
<R a="1" b="2">
<I attribute1="" attribute2="some text"/>
<I attribute1="" attribute2="some text"/>
<I attribute1="0" attribute2="some text"/>
<I attribute1="0" attribute2="some text"/>
</R>
Here I’ve to check if attribute1 is not null then I’ve to get value of attribute2 from I tag.How to do this???
Please help…
UPDATE:
Here’s a full X-browser working script that should do the trick. Again, replace the
getAttribute('attribute1')by either arguments or return the DOM and take care of the rest. This code might look a bit complicated (it uses closures to be as lightweight as possible) but it should be quite sturdy and safe to use… as long as you don’t declare another function calledparseXMLand you don’t call thisparseXMLprior to it being declared.You can parse the XML:
This snippet will log
some important text, and notsome text. That’s all there is to it. If you need to store thexvalues, or return them just declare another variable:This is assuming an
xproperty will be set, if that’s not always the case, an additional check can easily fix that. The full code will then look like: