473,386 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Find an xml node

Hello,

I have a xml file like this:

<book id='1'>
<name></name>
<author></author>
...
</book>

<book id='2'>
...
</book>

<book id='3'>
...
</book>

....
How to find the book with attribute id = '2' without cycle all nodes?

Thanks!
Marco / iw2nzm
Mar 29 '08 #1
2 1561
On Sat, 29 Mar 2008 18:00:38 GMT, Marco Trapanese
<ma******************@gmail.comwrote:
>Hello,

I have a xml file like this:

<book id='1'>
<name></name>
<author></author>
...
</book>

<book id='2'>
...
</book>

<book id='3'>
...
</book>

...
How to find the book with attribute id = '2' without cycle all nodes?
Can't do it, as far I am aware. You will have to restrieve a NodeList
on book, then cycle through the nodes looking for the first one that
has an attribute of id with the value of 2.

Well , technically, you are not cycling thorugh all nodes, since the
one you are looking far, at least in this example, is the second one.
But you will need to first retrieve the entire list of book nodes with
a SelectNodes method invocation.

Besides, by this time you have the entire XML file in memory anyway
from the DOM Load method.
Mar 29 '08 #2
On Mar 29, 2:00*pm, Marco Trapanese <marcotrapaneseNOS...@gmail.com>
wrote:
Hello,

I have a xml file like this:

<book id='1'>
* * * * <name></name>
* * * * <author></author>
* * * * ...
</book>

<book id='2'>
* * * * ...
</book>

<book id='3'>
* * * * ...
</book>

...

How to find the book with attribute id = '2' without cycle all nodes?

Thanks!
Marco / iw2nzm
It would be possible to find the element using a string search, but it
would be very difficult to find the matching end element without some
serious Regex overhead. Then you would be able to load the string you
found into memory as xml and parse it normally. I seriously doubt this
would give you better performance, and would be a huge pain to
maintenance.

Why exactly are you afraid to loop through the nodes?

Thanks,

Seth Rowe [MVP]
Mar 30 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Robert Mark Bram | last post by:
Hi All! In the code below, I am reading in an xhtml document and attempting to use selectNodes to find a <p id="rmb"> node.. But the result is: 2 - */* 0 - */p Can anyone suggest what I...
3
by: mike | last post by:
I have an xml structure like: <data> <struct>1,8,7,30</struct> </data> and I need to develop a test that finds this node in each of these cases, something like: should find because 1 is...
3
by: Robert Oschler | last post by:
What's a good way to find a specific text node element in a web page's DOM tree? I thought of traversing each node but there has to be a faster way. Is there a "find text node by nodeValue"...
9
by: Bernd.Moos | last post by:
Given the following XML document: <text> <p> <w>Ronaldo</w> <w>scoredw> <w>the</w> <w>1</w> <c>:</c> <w>1</w>
2
by: Raed Sawalha | last post by:
I have following XML: How can I find the depth of XML? in other word max level of the XML <Root> ----- level 0 <Name>----- level 1 <FirstName>name</FirstName> ---- level 2...
5
by: Jeroen Ceuppens | last post by:
I need to put a new node at the end of the tree, that end is not te lowest in de list but the deepest (the one with the most + before it) Node A Node 1 Node 2 Node 3 Node 4: Deepest Node B:...
21
by: Imran | last post by:
I have a vector of integers, such as and I want to find out the number which occurs most frequently.what is the quick method. My array size is huge. what I am doing is 1. find out the...
9
by: anunaygupta | last post by:
Hello all, I have a data structures problem. Assume there are 2 linked lists L1 and L2. They merge into some node. L1 1->2->3->4->5->6 / L2 8->7->9->/ L1 and L2 merge in node with value...
2
by: andreas | last post by:
Hi, I have a problem with treenode I know the node.text of a selected node in a variable and then some nodes are removed but not the selected node who is no more selected (so using index and...
1
by: xetulul | last post by:
my problem is that im unable to match a user input word to a word in a string. the strings are in a file and then placed in nodes. i have to go through each token in each node to find the 'word'....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.