DOM PARSER

Discussion in 'XML' started by Sukanta, Nov 22, 2004.

  1. Sukanta

    Sukanta Guest

    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
     
    Sukanta, Nov 22, 2004
    #1
    1. Advertising

  2. Sukanta

    Piet Guest

    (Sukanta) wrote in message news:<>...
    > 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
     
    Piet, Dec 5, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thorsten Meininger
    Replies:
    0
    Views:
    443
    Thorsten Meininger
    Jul 28, 2004
  2. Thorsten Meininger
    Replies:
    0
    Views:
    511
    Thorsten Meininger
    Jul 28, 2004
  3. mike
    Replies:
    1
    Views:
    1,147
    Martin Honnen
    Nov 20, 2004
  4. Replies:
    0
    Views:
    557
  5. Replies:
    3
    Views:
    536
    Stefan Behnel
    Aug 3, 2007
Loading...

Share This Page