← Prev in month ← Prev in thread

extract the value attribute of a node in a xml file.

From
Nishi Prafull <>
To
Date
2005-04-20T19:47:05Z
ID
<>
Thread
extract the value attribute of a node in a xml file.
Hi:

I have an info.xml file containing the following

<Targets AGENT_SEED="195839280">
<Target TYPE="info_apache" DISPLAY_NAME="HTTP_Server" VERSION="2.0">
<Property NAME="HTTPPort" VALUE="7779"/>
</Target>
</Targets>

There will be other such <Target/> entries in the file but I need to
only extract the value of the Property called HTTPPort using DOM
Parser.

Will the following code work -->

URL info_xml_url = new URL("file://" + "/temp/info.xml");
XMLDocument xmlDocument = null;
NodeList nodeList = null;

DOMParser parser = new DOMParser();
parser.parse(info_xml_url);
xmlDocument = parser.getDocument();

nodeList=xmlDocument.selectNodes("/Targets//target/property");
for(int i=0; i<nodeList.length(); i++)
{
if (XMLElement)nodeList.item(i). getAttribute("name").equals("HTTPPort")
{
   String port_val = node.getAttribute("value");
}
}

Please let me know.

Thanks.
← Prev in month ← Prev in thread