473,396 Members | 2,003 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,396 software developers and data experts.

get namaspaces for element

Hi,

I'm trying to figure out the xpath-expression for getting all relevant
namespaces of an element, but I don't wangle it.

When I have this document:

<A xmlns1>
<B xmlns2></B>
<C xmlns3>
<D>xxx</D>
<E></E>
</C>
</A>

....I need an expression which gives me the namespaces for <D>, that is
xmlns1 xmlns3

or even better, an expression which has the result
<D xmlns1 xmlns2>xxx</D><E></E>

BTW I'm not using xpath within xsl...I just need the plain expression.

Thanks.
Jul 20 '05 #1
11 1553


Tommy Frost wrote:
I'm trying to figure out the xpath-expression for getting all relevant
namespaces of an element, but I don't wangle it.

When I have this document:

<A xmlns1>
<B xmlns2></B>
<C xmlns3>
<D>xxx</D>
<E></E>
</C>
</A>
What is that above? It is not even well-formed.
...I need an expression which gives me the namespaces for <D>, that is
xmlns1 xmlns3

or even better, an expression which has the result
<D xmlns1 xmlns2>xxx</D><E></E>


I can't follow what you want as the initial example is not even
well-formed, if you want to know the namespace URI of a node you can use
the XPath 1.0 function namespace-uri().
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Martin Honnen wrote:
What is that above? It is not even well-formed.
Sorry...I mixed it up a little.

<?xml version="1.0"?>
<A xmlns1>
<B xmlns2/>
<C xmlns3>
<D>xxx</D>
</C>
</A>
if you want to know the namespace URI of a node you can use
the XPath 1.0 function namespace-uri().


No, I want all namespaces that effect a certain element, e.g. <D> -> xmlns1,
xmlns3

Jul 20 '05 #3


Tommy Frost wrote:
Martin Honnen wrote:

What is that above? It is not even well-formed.

Sorry...I mixed it up a little.

<?xml version="1.0"?>
<A xmlns1>
<B xmlns2/>
<C xmlns3>
<D>xxx</D>
</C>
</A>


That is not well-formed. Are you sure you understand XML namespaces at all?
http://www.w3.org/TR/REC-xml-names/


--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #4
>> <?xml version="1.0"?>
<A xmlns1>
<B xmlns2/>
<C xmlns3>
<D>xxx</D>
</C>
</A>


That is not well-formed. Are you sure you understand XML namespaces at
all?
http://www.w3.org/TR/REC-xml-names/


As far as I know, wellformed means:
- xml-declaration
- at least one element
- one root-element

....but the question remains the same
Jul 20 '05 #5
In article <c0*************@ID-16539.news.uni-berlin.de>,
Tommy Frost <th***@t-online.de> wrote:
No, I want all namespaces that effect a certain element, e.g. <D> -> xmlns1,
xmlns3


What form do you want them in? The namespace axis gives you the
namespace nodes that apply to an element (e.g. //D/namespace::*), but
how you do something with those nodes depends on what you're using
XPath in.

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!
Jul 20 '05 #6
In article <c0*************@ID-16539.news.uni-berlin.de>,
Tommy Frost <th***@t-online.de> wrote:
% >> <?xml version="1.0"?>
% >> <A xmlns1>
% >> <B xmlns2/>
% >> <C xmlns3>
% >> <D>xxx</D>
% >> </C>
% >> </A>
% >
% > That is not well-formed. Are you sure you understand XML namespaces at
% > all?
% > http://www.w3.org/TR/REC-xml-names/
%
% As far as I know, wellformed means:
% - xml-declaration

[not required]

% - at least one element
% - one root-element

- every attribute has a value, in quotes

Let's guess at what you mean

<A xmlns='data:text/plain,my-namespace-1'>
<B xmlns='data:text/plain,my-namespace-2'>
<C xmlns='data:text/plain,my-namespace-3'>
<D>xxx</D>
</C>
</B>
</A>

and you want to know what name spaces apply to D. The answer is that
only 'data:text/plain,my namespace 3' does. In XSLT, you might get
at it like this

<xsl:template match='*[local-name() = "D"'>
<xsl:text>Namespace for D is </xsl:text>
<xsl:value-of select='concat(namespace-uri(), ".")'/>
</xsl:template>

If your goal is to force this to appear as an xmlns in the declaration of D,
I'm not sure it's possible to do that consistently.
--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #7
> That is not well-formed. Are you sure you understand XML namespaces at
all?


I was told by mail that people might think, that I consider xmlns1 etc. as
"real" namespaces -> No - they're just short forms of real ones. Thought
this was clear.

Jul 20 '05 #8
> What form do you want them in? The namespace axis gives you the
namespace nodes that apply to an element (e.g. //D/namespace::*), but
how you do something with those nodes depends on what you're using
XPath in.


I'm using a java-prog which awaits an xpath-expression and a xml-doc. The
matching nodes are returned.
"//D/namespace::*" doesn't work, the result is empty...btw "//D" only works,
when there are no namespaces that apply to D...strange

Jul 20 '05 #9
ah... I found out that "//D/namespace::*" actually works - but only as long
as there are namespaces with prefixes like
"xmlns:xm="http://www.someurl.org"". As soon as default namespaces
(xmlns="http://www.someurl.org") appear, it doesn't work...
Jul 20 '05 #10
In article <c0*************@ID-16539.news.uni-berlin.de>,
Tommy Frost <th***@t-online.de> wrote:
"//D/namespace::*" doesn't work, the result is empty...btw "//D" only works,
when there are no namespaces that apply to D...strange


//D will only work when D is in no namespace, that is, when there is
no default namespace. If D is in a namespace because there is a
default namespace (i.e. xmlns="something"), you will have to bind a
prefix to refer to it in the XPath expression. You will need
something like //foo:D and //foo:D/namespace::*, but I don't know how
you bind a prefix in the system you're using.

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!
Jul 20 '05 #11
In article <c0*************@ID-16539.news.uni-berlin.de>,
Tommy Frost <th***@t-online.de> wrote:
% > That is not well-formed. Are you sure you understand XML namespaces at
% > all?

% I was told by mail that people might think, that I consider xmlns1 etc. as
% "real" namespaces -> No - they're just short forms of real ones. Thought
% this was clear.

That was clear. It's not at all clear what you mean, though, so how about
a short but complete example showing what you want as input and what
you want as output?

--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #12

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

Similar topics

1
by: Igor | last post by:
Is there any way to resort and xml document using xslt based on element position. For example if I have xml like this: <root> <element> 1st thing </element> <element> 2nd thing </element>...
4
by: Gordon Dickens | last post by:
I have target xml to generate from schema. All of the XML instances have the same global element i.e. <base>. I would like to combine all of the schemas into a single schema where I could...
6
by: Wole Ogunremi | last post by:
I guess this is a well asked question but it is tripping me up! I'm putting a forum together allowing xhtml markup content. I am validating against a schema but getting "Could not find schema...
0
by: Leo | last post by:
In my XML file, I have to elements: "person" and "organization", which are exchangable. Since these two elements are nearly identical, I plan to write an abstract element "agent" in my schema and...
5
by: Patient Guy | last post by:
In my reading of the Strict and Transitional DTD for HTML 4.0, the table row (TR) elements are contained within table section elements: THEAD, TFOOT, and TBODY. The table section elements are...
6
by: Luke Dalessandro | last post by:
I'm not sure if this is the correct forum for platform specific (Mozilla/Firefox) javascript problems, so just shout and point me to the correct newsgroup if I'm being bad. Here's the deal... ...
1
by: unwiseone | last post by:
Hello, Does any know how to specify a value of a DTD element? For example, here's an external DTD that I have: ======================================= <!ELEMENT summercamps (Camp+)>...
4
by: patrizio.trinchini | last post by:
Hi all, I'm new to XSLT and maybe my problem have a very trivial answer, but I need an expert that point me in the right direction. What I would obtain is to remove all the elements that have a...
2
by: mlb5000 | last post by:
I seem to be having issues validating an XML document using my schema. Both are below: The Schema: <?xml version="1.0" encoding="UTF-8"?> <xs:schema...
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
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
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...
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,...

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.