You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by Brett McLaughlin <br...@earthlink.net> on 2000/03/01 05:27:33 UTC

Late night DOM question

I must be getting stupid as the night wears on... can someone point me in the direction in what error I am making?

For the following XML document:

<?xml version="1.0"?>

<JavaXML:xmlrpc-config xmlns:JavaXML="http://myUrl.com">
  <JavaXML:hostname>localhost</JavaXML:hostname>
  <JavaXML:port type="unprotected">85</JavaXML:port>
</JavaXML:xmlrpc-config>

and this code snippet:

try {
    DOMParser parser = new (org.apache.xerces.parsers.)DOMParser();
    parser.parse(uri);    // Parse supplied document
    Document doc = parser.getDocument();

    NodeList nodes = doc.getElementsByTagName("JavaXML:hostname");
    if (nodes.getLength() > 0) {
      hostname = nodes.item(0).getNodeValue();
    }

    nodes = doc.getElementsByTagName("JavaXML:port");
    if (nodes.getLength() > 0) {
      portNumber = (Integer.parseInt(nodes.item(0).getNodeValue());
    }
} // exception handling

this never pulls any data out for me.  However,

NodeList nodes = doc.getElementsByTagName("*");
and then printing each node's getNodeName() result gives me:

JavaXML:xmlrpc-config
JavaXML:hostname
JavaXML:port

What am I missing?

Thanks,
Brett

Re: Late night DOM question

Posted by Chris Gokey <cg...@hydrogen.stx.com>.
Hi Brett,

I believe you are missing:

Element root = doc.getDocumentElement();

-then- call:

NodeList nodes = root.getElementsByTagName("JavaXML:hostname");
if (nodes.getLength() > 0) {
   hostname = nodes.item(0).getNodeValue();
}

nodes = root.getElementsByTagName("JavaXML:port");
   if (nodes.getLength() > 0) {
   portNumber = (Integer.parseInt(nodes.item(0).getNodeValue());
}

Chris

and then from there, call

> Brett McLaughlin wrote:
> 
> I must be getting stupid as the night wears on... can someone point me in
> the direction in what error I am making?
> 
> For the following XML document:
> 
> <?xml version="1.0"?>
> 
> <JavaXML:xmlrpc-config xmlns:JavaXML="http://myUrl.com">
>   <JavaXML:hostname>localhost</JavaXML:hostname>
>   <JavaXML:port type="unprotected">85</JavaXML:port>
> </JavaXML:xmlrpc-config>
> 
> and this code snippet:
> 
> try {
>     DOMParser parser = new (org.apache.xerces.parsers.)DOMParser();
>     parser.parse(uri);    // Parse supplied document
>     Document doc = parser.getDocument();
> 
>     NodeList nodes = doc.getElementsByTagName("JavaXML:hostname");
>     if (nodes.getLength() > 0) {
>       hostname = nodes.item(0).getNodeValue();
>     }
> 
>     nodes = doc.getElementsByTagName("JavaXML:port");
>     if (nodes.getLength() > 0) {
>       portNumber = (Integer.parseInt(nodes.item(0).getNodeValue());
>     }
> } // exception handling
> 
> this never pulls any data out for me.  However,
> 
> NodeList nodes = doc.getElementsByTagName("*");
> and then printing each node's getNodeName() result gives me:
> 
> JavaXML:xmlrpc-config
> JavaXML:hostname
> JavaXML:port
> 
> What am I missing?
> 
> Thanks,
> Brett

-- 
Christopher D. Gokey, Raytheon ITSS, NASA/GCMD
18 Martin Road, Shelburne Falls, MA  01370
Phone: Voice (413) 625-8129 / FAX 208-248-9055
cgokey@gcmd.nasa.gov / http://gcmd.nasa.gov