473,769 Members | 4,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1575


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:tex t/plain,my-namespace-1'>
<B xmlns='data:tex t/plain,my-namespace-2'>
<C xmlns='data:tex t/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>Names pace 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.c om
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

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

Similar topics

1
3385
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> <element> 3rd thing </element> </root> would it be possible using xslt only to reverse it into:
4
2395
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 generate any of the specific instances. sample schema one: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="base">
6
2467
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 information for element <elementName>... I would appreciate if anyone could advice where I am going wrong. TIA Here's my xsd:
0
1348
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 let "person" and "organization" inherit from "agent". However, my schema is invalid. Can anyone please point out what my problem is. Thanks a million in advance! Leo The following is my XML instance file:
5
3125
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 the defined contents of the TABLE element. The TR element is not defined as an "immediate" or "direct" contained element of TABLE. Given that
6
13378
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... html file (generated using .NET 2.0 beta2): <form method="post" action="Test2.aspx" id="form1">
1
1292
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+)> <!ELEMENT Camp (name, campcode?, ContactPhone, ContactPhone?, Activity+)>
4
2923
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 child element with an attribute set at a given value; maybe an example is more self-explaining... Given the following input XML document:
2
18152
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 xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Receivers" > <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element ref="MulticastReceiver"/>
0
9415
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9978
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8860
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7392
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5432
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3947
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3551
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.