[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

  • To: Michael Kay <mike@s...>
  • Subject: Re: extract the value attribute of a node in a xml file.
  • From: Nishi Prafull <nishiprafull@g...>
  • Date: Thu, 21 Apr 2005 10:25:53 -0700
  • Cc: xml-dev@l...
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=JhPKwV6aKQBK6+SnpIO7OkdpbnhgIms+vAaiwFJN/jFheY9A7u3Nh8/n9sVfQe8ef1Whp4+vYmrStNE3XQNzjjF7rWHZD/rpSUzAIyH22Fj0WokYwwaEbEm1ys3JSEHTxqPqgO+2A9zBu2kvH29nDX/fyFeYRyqlhnOr4Bb0j3A=
  • In-reply-to: <426765e1.0ddfe7eb.1b6a.6959SMTPIN_ADDED@m...>
  • References: <c540fe2605042012471afac095@m...> <426765e1.0ddfe7eb.1b6a.6959SMTPIN_ADDED@m...>
  • Reply-to: Nishi Prafull <nishiprafull@g...>

extract values from 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@s...> 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@g...]
> > Sent: 20 April 2005 20:47
> > To: xml-dev@l...
> > Subject:  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>
> 
>

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.