473,405 Members | 2,154 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,405 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 2213
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.