?
Solved

XML Node Access

Posted on 2003-03-03
4
Medium Priority
?
347 Views
Last Modified: 2013-11-19
Hi everybody,

I have a strange problem here, might look simple but am not gettin' the stuff....

I just wannu access a node in an XML file based on its count.

say I have .DomDocument.DocumentElement.childnodes.length yielding me 10 and I have to access the contents(children) of 8th node.
n this has to be carried out dynamically.

cld anyone of u plz help me with this??


Thanks
Anand
0
Comment
Question by:anandpatil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Accepted Solution

by:
JamesBaud earned 200 total points
ID: 8057968
The easiest way to do this is to use XPath.  With XPath, you can get to the exact node you're looking for without having to create other node objects to get there.

See link below:
http://www.w3.org/TR/1999/REC-xpath-19991116

Not sure which language you're using or I'd post a more specific example.
0
 
LVL 1

Assisted Solution

by:yossigordin
yossigordin earned 200 total points
ID: 8063148
Hi Anand,
for example if you have an xml file and you make an object xmlSrc based on that file.And say you have a root element named HOMEPAGE and it has 10 children (or more)

var nodelist=xmlSrc.selectNodes("//HOMEPAGE);

nodelist[0].childNodes[7].text -->will give you the innerText of the 8th node

nodelist[0].childNodes[7].getAttribute("id"); -->will give you the attribute "id" (if you assign it).
nodelist is an array of root elements and because you have only one, nodelist[0] is the only root element.

Hope it helps you,

Regards,
yossigordin

0
 

Expert Comment

by:CleanupPing
ID: 9447397
anandpatil:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
Make the most of your online learning experience.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question