DOM PARSER

S

Sukanta

Hi,
Below is my XML file with some Platform and feature name. I have to
show the platform name in a drop down list.
How I will write a DOM parser for this.

<?xml version="1.0" encoding="UTF-8"?>
<Platformlist>
<Platform Name="A90-610010" type="xyz" customer="HSS">
<Feature Name="LAN Configuration"/>
<Feature Name="WAN Configuration"/>
<Feature Name="Firewal Settings"/>
</Platform>
<Platform Name="B90-600085" type="xyz" customer="HSS">
<Feature Name="Firewall Settings"/>
<Feature Name="WAN Configuration"/>
</Platform>
<Platform Name="C90-610010" type="xyz" customer="HSS">
<Feature Name="Firewall Settings"/>
<Feature Name="WAN Settings"/>
</Platform>
</Platformlist>

Thanks in advance.

Sukanta
 
P

Piet

Hi,
Below is my XML file with some Platform and feature name. I have to
show the platform name in a drop down list.
How I will write a DOM parser for this.
Hello Sukanta,
parsing an Xml document (i. e. transforming the stream of bytes into a
tree-like structure) is one thing, but displaying the information in
some GUI is an entirely different thing. Its implementation will
strongly depend on the programming language that you want to use.
Some pseudo-code in Java will look like this. In this example, it is
assumed that apache Xalan is in the classpath, because it is used as a
source for the xpath engine. You may also want to use JAXP 1.3 (part
of Java 1.5).
Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("PathToXmlFile.xml");
Node root = dom.getDocumentElement();
NodeList nodes = XPathAPI.selectNodeList(root,"Platform");
JComboBox box = new JComboBox();
for (int i=0;i<nodes.getLength();i++){
box.addItem(nodes.item(i).attributes.getNamedItem("Name").getNodeValue())
}
That should generate a JComboBox in which your "Platform"-Nodes are
represented by their "Name"-attribute.
BW
Piet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top