473,386 Members | 1,812 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.

Using xPath to Search Entire xml file

ETL
Hi,
I have an xml document that feeds a treeview menu on my web site. The
structure of the xml file is as follows.

<XML type="text/xml">
<root>
<a0 name="One">
<a0_0 html="Report 1" id="1" />
<a0_1 html="Report 2" id="2" />
<a0_2 html="Report 3" id="3" />
</a0>
<a1 name="Two">
<a1_0 html="Report 1" id="4" />
<a1_1 html="Report 2" id="5" />
<a1_2 html="Report 3" id="6" />
</a1>
<a2 name="Three">
<a2_1 name="Three_One">
<a2_1_1 html="Report 1" id="7" />
<a2_2_2 html="Report 2" id="8" />
</a2_1>
<a2_2 name="Three_Two">
<a2_2_1 html="Email Report 1" id="9" />
<a2_2_2 html="Email Report 2" id="10" />
<a2_2_3 html="Email Report 3" id="11" />
</a2_2>
</a2>
</root>
</XML>

I want to buld an asp.net application that takes in a node id attribute
and returns the html attribute of the desired node. So if 11 were
passed in it would return "Email Report 3".

I've found lots of xPath examples that search a straigh aligned xml
file that doesn't have nested attributes but my file is more complex
and includes tierded menu folders.

How can I search the entire document for the ID attribute.

One other thing, is there a difference in xPath quesries when using
attribute or element based xml? Just curious.
Thanks for your help.

Regards

Eric

Jul 20 '05 #1
9 5743


ETL wrote:

I have an xml document that feeds a treeview menu on my web site. The
structure of the xml file is as follows.

<XML type="text/xml">
<root>
<a0 name="One">
<a0_0 html="Report 1" id="1" />
<a0_1 html="Report 2" id="2" />
<a0_2 html="Report 3" id="3" />
</a0>
<a1 name="Two">
<a1_0 html="Report 1" id="4" />
<a1_1 html="Report 2" id="5" />
<a1_2 html="Report 3" id="6" />
</a1>
<a2 name="Three">
<a2_1 name="Three_One">
<a2_1_1 html="Report 1" id="7" />
<a2_2_2 html="Report 2" id="8" />
</a2_1>
<a2_2 name="Three_Two">
<a2_2_1 html="Email Report 1" id="9" />
<a2_2_2 html="Email Report 2" id="10" />
<a2_2_3 html="Email Report 3" id="11" />
</a2_2>
</a2>
</root>
</XML>

I want to buld an asp.net application that takes in a node id attribute
and returns the html attribute of the desired node. So if 11 were
passed in it would return "Email Report 3".


Having the nesting level encoded in the element name is a pretty odd way
and will cause you a lot of trouble I think.
The XPath could be
//*[@id = '11']/@html

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
>> I want to buld an asp.net application that takes in a node id attribute
and returns the html attribute of the desired node. So if 11 were
passed in it would return "Email Report 3".


Having the nesting level encoded in the element name is a pretty odd way
and will cause you a lot of trouble I think.
The XPath could be
//*[@id = '11']/@html


Maybe you could use the DOM function 'getElementById' instead of an Xpath expression?
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Vincit omnia simplicitas
Jul 20 '05 #3
ETL

Joris Gillis wrote:
I want to buld an asp.net application that takes in a node id attribute and returns the html attribute of the desired node. So if 11 were
passed in it would return "Email Report 3".
Having the nesting level encoded in the element name is a pretty odd way and will cause you a lot of trouble I think.
The XPath could be
//*[@id = '11']/@html


Maybe you could use the DOM function 'getElementById' instead of an

Xpath expression?

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041) Vincit omnia simplicitas


I'm not so sure that the 'getElementById' format works for nested
nodes. All the exmples I found for this used simple one dimensional XML
documents.

Jul 20 '05 #4
ETL

Joris Gillis wrote:
I want to buld an asp.net application that takes in a node id attribute and returns the html attribute of the desired node. So if 11 were
passed in it would return "Email Report 3".
Having the nesting level encoded in the element name is a pretty odd way and will cause you a lot of trouble I think.
The XPath could be
//*[@id = '11']/@html


Maybe you could use the DOM function 'getElementById' instead of an

Xpath expression?

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041) Vincit omnia simplicitas


I'm not so sure that the 'getElementById' format works for nested
nodes. All the exmples I found for this used simple one dimensional XML
documents.

Jul 20 '05 #5


Joris Gillis wrote:
Having the nesting level encoded in the element name is a pretty odd way
and will cause you a lot of trouble I think.
The XPath could be
//*[@id = '11']/@html


Maybe you could use the DOM function 'getElementById' instead of an
Xpath expression?


If you want to use getElementById then the document needs a DTD that
defines that the attributes of name id are of type ID. The original
example doesn't have a DTD. And with those element names encoding
nesting levels the DTD would need to be adjusted every time the nesting
level of the XML increases.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #6
> If you want to use getElementById then the document needs a DTD that
defines that the attributes of name id are of type ID. I'll try not to make that mistake again...
The original example doesn't have a DTD. And with those element names
encoding nesting levels the DTD would need to be adjusted every time the
nesting level of the XML increases.


Is it really necessary to define the whole DTD? Can one not specify the
attribute that is of type ID without including any other document
definition? (note that I've never used DTD, XML Schema or RelaxNG)

regards,
--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 20 '05 #7


Joris Gillis wrote:
Is it really necessary to define the whole DTD? Can one not specify the
attribute that is of type ID without including any other document
definition?


With a DTD you need to define the attribute for each element you want to
use it on.
I am not sure what is supposed to happen if you do not define the
elements but then specify attributes but it is certainly not reliable
thing to do.
In my tests here with MSXML 3 and with .NET XmlDocument elements are not
found by id (using the nodeFromID function in MSXML and GetElementById
with .NET) if only attributes are defined.
Mozilla with getElementById finds the elements if only the attributes
are defined. But Mozilla only processes internal subsets of DTDs so in
many cases you can't rely on ID attributes and getElementById.
There is a new W3C recommendation for the xml:id attribute
<http://www.w3.org/TR/xml-id/>
if that is going to be implemented then no DTD should be required to
make use of getElementById.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #8
> There is a new W3C recommendation for the xml:id attribute
<http://www.w3.org/TR/xml-id/>
if that is going to be implemented then no DTD should be required to
make use of getElementById.


That sounds really interesting. I hope it will soon become a recommendation...

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
"Scio me nihil scire" - Socrates
Jul 20 '05 #9
ETL

Joris Gillis wrote:
There is a new W3C recommendation for the xml:id attribute
<http://www.w3.org/TR/xml-id/>
if that is going to be implemented then no DTD should be required to make use of getElementById.
That sounds really interesting. I hope it will soon become a

recommendation...
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041) "Scio me nihil scire" - Socrates


lame....it's looking like GetElementByID is going to be too much
overhead for this application. I don't want to have to maintain a DTD
for this. Back to xPath solution I guess.....

Jul 20 '05 #10

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

Similar topics

2
by: Anna | last post by:
Hi all. I am using Jaxen to evaluate XPath expressions in Java. I encountered problems when comparing results returned by jaxen with results returned by other XPath implementation - I was using...
3
by: Alexander Gräf | last post by:
Hello, I'm stuck with a simple problem, for which I don't have a solution. I basically have an XML file containing fragments of plain text and html, in several languages: <?xml version="1.0"...
4
by: Ken Getz | last post by:
Hi. I have an xml file in this format: <strings> <string>Item1</string> <string>Item2</string> <string>Item3</string> <string>Item4</string> </string> I'm looking for the best way to...
6
by: Chua Wen Ching | last post by:
Hi there, I had this xml file with me (not yet consider implementing xml namespaces yet). <?xml version='1.0'?> <Object> <Windows> <EID>1</EID> <EDesc>Error 1</EDesc> </Windows>
3
by: Yair Cohen | last post by:
hello 1 i use an xml documet with xml schema but when i try to use XPath (selectnodes) it retrieves empty list. when i remove the schema (the 'xmlns="http..."') i get the data. how can i handle...
1
by: suresh.csharp | last post by:
Hi, I am trying to import huge data into XML files it is in more than 700Mbs, creating a index(catalog) XML file for all the imported XML files for searching xml files content. The idex(catalog)...
2
by: Kevin Burton | last post by:
I have determined that the following XPath expression: //Message/OrderReport/Item/Quantity gives me all of the "Quantity" nodes and //Message/OrderReport/Item/ItemPrice/Component/Amount ...
2
by: Bilal | last post by:
Hello, I'm stuck on this problem for quite some time and hope somebody would be able to guide me. Basically, I need to populate a large number of "template" XML files which have all...
6
by: Derek Hart | last post by:
I bring in an xml file into vb.net by using xmlDoc.LoadXml(XMLString) - I run xpath statements against the xml file to grab data from it, so I use, as an example, //Vehicles/Vehicles/@make to get...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.