Hello. I've looked around some and haven't found a good tutorial on this. I've got an XML file in the format of:
The <item> element is repeating and optional, and I don't know in general how many there will be. However I need to use DOM to go through and gather each of the strings located in the <item> elements. However this should only be done in <item> elements within the <inventory> tag, not in any of the other elements. A lot of the tutorials don't cover how to work with repeating elements and are low-quality, so that's why I'm asking this question here. What's a really simple and easy-to-understand way to do this? If you know of a good tutorial that covers dealing with repeating, nested elements, please link it. Thanks!
You should change it to use XPath. You are selecting zero records because there aren't any elements with that name, which in any case isn't even a valid XML element name.
How so? I thought that was what I was doing when placed the "/root/inventory/item" in there, instead of just a tag name. I'm just starting out on parsing XML in Java, so what does my code snippet need to be changed to?
However this should only be done in <item> elements within the <inventory> tag, not in any of the other elements.
Its scope is meant more generally to have item being "descendant" of inventory rather than only an immediate child element of it. If you want strictly immediate child only, try your own know-how based on the above.>
Thank you! That worked excellently. I'm not using any grandchildren inside the inventory element, so that'll work fine. As for the links earlier, sorry, I thought that was just this site looking at keywords in your message and adding stuff in automatically.