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

Navigating namespace declarations

I have to process the xmlns declarations in the root node of a
document.
Unfortunately, they are not recognized as elements nor as attributes.
Even with a /root/node() I can't reach them.

example:
<root xmlns="http://foo1" xmlns:a="http://foo2">
....
</root>

I'm wondering how to iterate through "xmlns" and "xmlns:a".

Regards,
Sébastien

May 10 '07 #1
4 1651
In article <11**********************@e51g2000hsg.googlegroups .com>,
Sébastien Ros <se**********@gmail.comwrote:
>I have to process the xmlns declarations in the root node of a
document.
Unfortunately, they are not recognized as elements nor as attributes.
Even with a /root/node() I can't reach them.
I assume you're using XPath. If so, there's no way to do it, because
namespace declarations do not appear in the XPath data model.

There are namespace nodes, which can be accessed with the namespace
axis, but they correspond to the namespaces in scope for an element,
not the ones declared on it. For example, in

<foo><bar xmlns:a="1"><baz/></bar></foo>

both bar and baz have a namespace node with name "a".

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
May 10 '07 #2
SĂ©bastien Ros <se**********@gmail.comwrote in
<11**********************@e51g2000hsg.googlegroups .com>:
I have to process the xmlns declarations in the root node
of a document.
Unfortunately, they are not recognized as elements nor as
attributes. Even with a /root/node() I can't reach them.
And if you think about it, it makes a lot of sense, too.
After all:

<root xmlns="http://example.org/foo">
<foo>
<bar/>
</foo>
</root>

is supposed to be equivalent to:

<foo:root xmlns:foo="http://example.org/foo">
<bar:foo xmlns:bar="http://example.org/foo">
<baz:bar xmlns:baz="http://example.org/foo"/>
</bar:foo>
</foo:root>

In a sense, xmlns declarations are merely syntactic sugar so
that we wouldn't have to write:

<{http://example.org/foo}foo>
<{http://example.org/foo}bar>
<{http://example.org/foo}baz/>
</{http://example.org/foo}bar>
</{http://example.org/foo}foo>

all the time. Because that's what both of the documents
above "really" mean. But, boy, wouldn't *that* be
cumbersome? So we have xmlns declarations, but they're
really just a serialization detail as far as many XML tools
are concerned.

--
Pavel Lepin
May 10 '07 #3
Sébastien Ros <se**********@gmail.comwrites:
I have to process the xmlns declarations in the root node of a
document.
Unfortunately, they are not recognized as elements nor as attributes.
Even with a /root/node() I can't reach them.

example:
<root xmlns="http://foo1" xmlns:a="http://foo2">
...
</root>

I'm wondering how to iterate through "xmlns" and "xmlns:a".
XPath has a namespace axis, and XPath data model explicitly provides
"namespace nodes". So:

<xsl:template match="whateverelementtype">
<xsl:for-each select="namespace::node()">
<xsl:variable name="prefix" select="local-name()"/>
<xsl:variable name="uri" select="."/>
...
</xsl:for-each>
</xsl:template>

should work. At least, it works with libxslt's xsltproc. (You even get
an "xml" prefixed namespace with uri
"http://www.w3.org/XML/1998/namespace".)

-- Alain.
May 10 '07 #4
Exactly what I needed, thank you (voisin).

Sébastien

May 10 '07 #5

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

Similar topics

2
by: Anonymous | last post by:
How do I reference a namespace variable in a multi-file project? Do I use the keyword 'extern'? If so, does the word 'extern' modify the namespace or the individual variables within the...
3
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0"...
17
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example ...
1
by: JustSomeGuy | last post by:
I am writing classes and I want them to belong to mynamespace What is the syntax to say that the class I'm defining is a member of mynamespace? What is the scope of the syntax and how does one...
12
by: Alex Hunsley | last post by:
There's no really specific questions in this post, but I'm looking for people's thought on the issues within... The two main versions I've encountered for data pseudo-hiding (encapsulation) in...
14
by: Jon Rea | last post by:
I am currently cleaning up an application which was origainlly hashed together with speed of coding in mind and therefore contains quite a few "hacky" shortcuts. As part of this "revamping"...
32
by: toolmaster | last post by:
Since many of the modern computer languages have built-in namespace features, I can't understand why not add this feature into standard C. I've heard many people complain of the lacking of...
8
by: Simon Brooke | last post by:
I was debugging a new XML generator tonight and trying to determine why it wasn't working; and realised my dom printer does not output XML namespace declarations. My method to output an Element...
10
by: Andy Fish | last post by:
hi, I have an XSLT which is producing XML output. many of the nodes in the output tree contain namespace declarations for namespaces that are used in the source document even though they are...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.