473,321 Members | 1,877 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,321 software developers and data experts.

Alternative to GetElementById

I wish to select a node using the value of one of its attributes, i.e.

xml:
....
<tablelist>
<table name="table1">
...
</table>
<table name="table2">
...
</table>
...
</tablelist>
....

Method Call: element = xmlDoc.GetElementById("table1")

But from what I have been reading and tested this only works if I am
using DTD and the attribute is of type ID. I don't want to use a DTD
(already using XSD) so how can I either use this method or is there an
alternative that doesn't tie me to using DTD's?
Note, I know I can select all of the nodes in the <tablelist> node and
then loop but I would rather not as this list could be huge.

Thanks

Billy

Sep 27 '05 #1
3 5727
Ann
4
u can do it with xPathNavigator......as follows :

XPathDocument myXPathDocument = new XPathDocument(@"C:\globals\globalsInputs.xml");
XPathNavigator myXPathNavigator = myXPathDocument.CreateNavigator();
XPathNodeIterator myXPathNodeIterator;
myXPathNodeIterator = myXPathNavigator.Select ("//table[@id = '"+parameter+"']");

while(myXPathNodeIterator.MoveNext())
{
string text = myXPathNodeIterator.Current.Value;
}




I wish to select a node using the value of one of its attributes, i.e.

xml:
....
<tablelist>
<table name="table1">
...
</table>
<table name="table2">
...
</table>
...
</tablelist>
....

Method Call: element = xmlDoc.GetElementById("table1")

But from what I have been reading and tested this only works if I am
using DTD and the attribute is of type ID. I don't want to use a DTD
(already using XSD) so how can I either use this method or is there an
alternative that doesn't tie me to using DTD's?
Note, I know I can select all of the nodes in the <tablelist> node and
then loop but I would rather not as this list could be huge.

Thanks

Billy
Sep 27 '05 #2


Billy wrote:
I wish to select a node using the value of one of its attributes, i.e.

xml:
...
<tablelist>
<table name="table1">
...
</table>
<table name="table2">
...
</table>
...
</tablelist>
...

Method Call: element = xmlDoc.GetElementById("table1")

But from what I have been reading and tested this only works if I am
using DTD and the attribute is of type ID. I don't want to use a DTD
(already using XSD) so how can I either use this method or is there an
alternative that doesn't tie me to using DTD's?


Depending on the DOM implementation/API you use it might for instance be
possible to use an XPath expression e.g.
/tablelist/table[@name = 'table1']
to look for that element.
But you haven't told us anything on what DOM implementation you use so I
can't tell whether XPath is possible for you or not.

It might also suffice if your XSD declares the name attribute of <table>
elements to be of type ID so that getElementById works.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 27 '05 #3
Thanks Martin for a prompt reply,

It works a treat, i've seen that syntax before now you've shown me it
... I will hopefully now remember it.

Thanks very much for your time.

Note: I am implementing the DOM object using .net c# and xpath is
available.
Regards

Billy

*** Sent via Developersdex http://www.developersdex.com ***
Sep 27 '05 #4

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

Similar topics

5
by: Colin Steadman | last post by:
I'm looping through an array of employee numbers and sending them to an Oracle procedure for processing. While I'm doing this I'm updating a <DIV> tag in the browser with index number of the...
10
by: Gernot Frisch | last post by:
Hi, I have found some menu functions. It works quite well, but how can I replace it with a simple <a href> if javascript is turned off? I reduced my code to:...
4
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
3
by: japi | last post by:
Hi, In my webpage I have an embedded Windows Media Player and an unordered list with a table of contents. When playing a video, the Windows Media Player is triggering events for new...
7
by: =?iso-8859-1?q?Jesper_R=F8nn-Jensen?= | last post by:
Hi. I just ran into a situation where I want to emulate the IE specific obj.click() syntax on an object on the webpage. The most convenient thing for me is if I were able to just select my ...
4
by: dr1ft3r | last post by:
Hey guys, I'm building a site for a landscaping business down the street and can't seem to get part of the code functioning correctly. The code fails on line 68 where I make a reference to an...
5
by: jhappeal | last post by:
I do not know Javascript that well so I might be going about this the wrong way. Any help would be appreciated. This function attempts to hide the options inside of the optgroup tag of the second...
4
by: spamme | last post by:
Hi, As you can see from the following code, I am trying to manipulate a large number of layers. I have read many times in the past how the "Eval" function should be used very sparingly as it can...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.