472,961 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Can XPath expressions use a default namespace?


The definition of XPath 1.0 says

"A QName in the node test is expanded into an expanded-name using the
namespace declarations from the expression context. This is the same
way expansion is done for element type names in start and end-tags
except that the default namespace declared with xmlns is not used: if
the QName does not have a prefix, then the namespace URI is null (this
is the same way attribute names are expanded). It is an error if the
QName has a prefix for which there is no namespace declaration in the
expression context."

As implementor of a program which uses XPath expressions to refer to
XML elements (the XPath expressions being sometimes embedded within
XML instance documents, sometimes supplied by other means), it seems
useful to me to let the program supply a default namespace (if
relevant) to the XPath expressions (*) and for XPath to be able to use
it for unprefixed names.

(*) or even let a larger environment than the XML instance document
determine what an unprefixed element means. For example if two
documents are visible, each wholly within its own namespace, with
top elements respectively "top1" and "top2", the expression
"/top1" would be unique without mentioning the namespace.

But the quoted text above seems to perhaps disallow this, forcing the
interpretation of an unprefixed name to imply the null namespace
instead of a defaulted one. Is that really the case?

(XSLT does enforce this, as does the program 'xmlstarlet', but this
of course does not prove anything one way or the other.)

Feb 9 '07 #1
1 2185
Arndt Jonasson wrote:
But the quoted text above seems to perhaps disallow this, forcing the
interpretation of an unprefixed name to imply the null namespace
instead of a defaulted one. Is that really the case?
Yes, with XPath 1.0 a name without a prefix selects an element or
attribute in no namespace.

With XPath 2.0 which is now a W3C recommendation things are different,
it introduces a default element/type namespace
<http://www.w3.org/TR/xpath20/#dt-def-elemtype-ns>
and that way a name without a prefix can select an element in that
default element namespace:
<http://www.w3.org/TR/xpath20/#node-tests>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 9 '07 #2

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

Similar topics

3
by: Bob | last post by:
Below is some code that use to work. Now it is not and I have yet to figure out why. I want to select the nodes to a nodelist and remove them from the dom. The only thing I can figure is it broke...
1
by: Seong-Tae Jeong | last post by:
for example, xml document is below, It has a default namespace "xmlns='qwer://test'". string xmlText = "<test xmlns='http://test'><clear/><clear/></test>"; I would like to select node list...
2
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file -...
3
by: Patrick | last post by:
Dear Ng, after I have loaded am XmlDataDocument file, I try to extract a single node via XmlElement myElem = (XmlElement)this.XmlDataDocument.SelectSingleNode("/Document/Headerdata/myElem");...
5
by: David Thielen | last post by:
Hi; I set up my xml as follows: XmlDocument xml = new XmlDocument(); xml.Load(File.Open("data.xml", FileMode.Open, FileAccess.Read)); XmlNamespaceManager context = new...
10
by: Michael C# | last post by:
OK, here's the deal. I have a small XML file that represents a small database table. I load it into a System.XML.XMLDocument. So far so good. I run an XPath query against it to retrieve all the...
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.