OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] extract the value attribute of a node in a xml file.

[ Lists Home | Date Index | Thread Index ]

1. Why are you using Oracle-specific classes when you could use the generic
JAXP/DOM interfaces?

2. You're still referring to the VALUE attribute in the wrong case. Why use
such a mixture of lower and upper case in your XML?

3. /Targets//Target could be more efficiently written /Targets/Target

4. getAttribute("NAME").equals("HTTPPort") will crash with an NPE if htere
is no NAME attribute

Apart from that I can't see anything wrong with the code from inspection,
but I'm not going to test it for you...

Michael Kay
http://www.saxonica.com/

 

> -----Original Message-----
> From: Nishi Prafull [mailto:nishiprafull@gmail.com] 
> Sent: 21 April 2005 18:26
> To: Michael Kay
> Cc: xml-dev@lists.xml.org
> Subject: Re: [xml-dev] extract the value attribute of a node 
> in a xml file.
> 
> Hi:
> 
> The lang is Java and the am using the Oracle XML DOM Parser
> So, will the below work for the below xml file--?
> 
> 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");
>  }
>  }
> 
> On 4/21/05, Michael Kay <mike@saxonica.com> wrote:
> > (a) You haven't said what language you think this code is 
> written in and
> > what API it is using. It looks a bit like Java but I don't 
> recognise the
> > classes DOMParser, XMLDocument, and XMLElement.
> > 
> > (b) XML is case sensitive so a search for "target" and 
> "property" and "name"
> > won't find nodes named "Target" and "Property" and "NAME".
> > 
> > Michael Kay
> > http://www.saxonica.com/
> > 
> > > -----Original Message-----
> > > From: Nishi Prafull [mailto:nishiprafull@gmail.com]
> > > Sent: 20 April 2005 20:47
> > > To: xml-dev@lists.xml.org
> > > Subject: [xml-dev] 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.
> > >
> > > -----------------------------------------------------------------
> > > The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> > > initiative of OASIS <http://www.oasis-open.org>
> > >
> > > The list archives are at http://lists.xml.org/archives/xml-dev/
> > >
> > > To subscribe or unsubscribe from this list use the subscription
> > > manager: <http://www.oasis-open.org/mlmanage/index.php>
> > >
> > >
> > 
> > -----------------------------------------------------------------
> > The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> > initiative of OASIS <http://www.oasis-open.org>
> > 
> > The list archives are at http://lists.xml.org/archives/xml-dev/
> > 
> > To subscribe or unsubscribe from this list use the subscription
> > manager: <http://www.oasis-open.org/mlmanage/index.php>
> > 
> >
> 






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS