Alternative to GetElementById

B

Billy

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
 
M

Martin Honnen

Billy said:
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.
 
B

Billy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,849
Latest member
Fira

Latest Threads

Top