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

XPath with different namespaces problem

I have XML:

<xml xmlns="http://abc">
<A t="ttt"></A>
<B xmlns="http://qwerty"><X>aaaa</X></B>
</xml>
How to point node "B" with XPath without any changes in this xml?

node A is pointed like this without any problem: /xml/A

but /xml/B points nothing. When remove xmlns="http://qwerty" it works!
Unfortunately I can't do any modification in this xml and add
namespace alias: xmlns:alias1="http://qwerty"

Feb 26 '07 #1
1 2250
On Feb 26, 8:32 am, sobczyk.wojci...@gmail.com wrote:
<xml xmlns="http://abc">
<A t="ttt"></A>
<B xmlns="http://qwerty"><X>aaaa</X></B>
</xml>
xml is a reserved name. From W3C's XML 1.0 FE, 2.3:

Names beginning with the string "xml", or with any string
which would match (('X'|'x') ('M'|'m') ('L'|'l')), are
reserved for standardization in this or future versions
of this specification.
How to point node "B" with XPath without any changes in
this xml?

node A is pointed like this without any problem: /xml/A

but /xml/B points nothing. When remove
xmlns="http://qwerty" it works! Unfortunately I can't do
any modification in this xml and add namespace alias:
xmlns:alias1="http://qwerty"
First of all, I suspect your XPath engine is broken. As far
as I can tell /xml/A should not match the node that is in a
namespace. At least libxslt and Saxon-8B seem to agree with
me.

Your XPath API should expose a method allowing you to
define namespace prefixes. Pseudocode:

xpathContext = new xpathContext ( whatever ) ;
xpathContext .
declareNsPrefix ( 'prefix' , 'http://qwerty' ) ;
xpathExpr =
xpathContext . makeXpathExpr ( '/xml/prefix:B' ) ;
nodesetFoo = xpathExpr . evaluate ( ) ;

In case your XPath API is so brain-dead it doesn't have
this feature, you can emulate the functionality with
namespace-uri() and local-name(). Note that this is ugly
and harmful for your mental well-being. You have been
warned.

Untested:

/xml/*
[namespace-uri()='http://qwerty' and local-name()='B']

--
Pavel Lepin

Feb 26 '07 #2

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

Similar topics

3
by: Colin Green | last post by:
I have come across what seems like a failing in the .Net XML classes. Many people have posted requesting how to write an XPath query with namespace prefixes that works. The solution shown in all...
4
by: Gismo | last post by:
I have got file raport.rld which is an XML file generated by MS Reporting Services. The problem is: in this file are tags from two different namespaces ...
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: SD | last post by:
Hi, How can i get all the nodes with attribute Name = "Publisher" or Name="Administrator" using XPath query and C# for this xml doc? <GetRoleCollectionFromUser...
14
by: Mat| | last post by:
Hello :-) I am learning XPath, and I am trying to get child nodes of a node whose names do *not* match a given string, e.g : <dummy> <example> <title>Example 1</title> <body>this is an...
6
by: J.Marsch | last post by:
I must be completely losing my mind. I have some code that writes to config files. It works great with app.config files, but fails miserably with web.config files. For the life of me, I cannot...
14
by: Mikhail Teterin | last post by:
Hello! What's would be the syntax for a query, which would allow me to get only the elements with non-empty text-nodes? For example, from: <a><b></b></a> <c/> <d><e>meow</e></d>
1
by: reyesvsn | last post by:
Hello everybody, I have a question concerning XPath expressions and namespaces. Consider this XML: <?xml version="1.0" encoding="UTF-8"?> <newsMessage ...
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...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.