I'm just starting to learn xml and I am having the following problem. I am triying to parse an Xml file(in
java) with the following structure, to create a Menubar:
<App>
<MenuBar NAME="TopMenu">
<Menu NAME="File" HANDLER="FileHandler">
<MenuItem NAME="FileOpen"LABEL="Open."/>
<MenuItem NAME="FileSave" LABEL="Save"/>
<MenuItem NAME="FileExit" LABEL="Exit"/>
</Menu>
<Menu NAME="Edit" HANDLER="EditHandler">
<MenuItem NAME="Undo" LABEL="Undo"/>
<MenuItem NAME="Cut" LABEL="Cut"/>
</Menu>
</MenuBar>
</App>
I am using apache parsers and trying to use XPATH statements as follows:
// find menu nodes
m_xpath = "//MenuBar/Menu";
NodeList MenuNodeList =
XPathAPI.selectNodeList(tmp_MenuBarNode, m_xpath);
for(int i=0; i < MenuNodeList.getLength(); i++)
{
System.out.println(
"Node Menu Value ----> " +i+ "= " + tmp_MenuNameList.item(i).getNodeValue());
/******* Below gets each menu item name ********/
xpath = "//MenuItem/@NAME";
NodeList MenuItemNameList = XPathAPI.selectNodeList(MenuNodeList.item(i), xpath);
for(int b=0; b< MenuItemNameList.getLength(); b++)
{
System.out.println("Node Item Value "+b+" = "+ MenuItemNameList.item(b).getNodeValue());
}
The code above Sytem.out's the Menu names correctly however it doesn't print the MenuItems correctly.
Any help would be greatly appreciated.
Thanks,
Stephen.