Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

XML Node Access

Posted on 2003-03-03
4
Medium Priority
?
361 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
3 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Progress
Loops Section Overview
Suggested Courses

580 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