List Info

Thread: Determing element namespace prefix




Determing element namespace prefix
user name
2007-01-02 23:41:34
Hi,

Is there a straightforward way to determine if an element has a namespace prefix? For the following element:

<myns:Elem> some data </myns:Elem>

I would like to obtain the string "myns:Elem". xmlNode.name simply returns "Elem" and I can't find an obvious way to get to the "myns" part as well.

Thanks,
Aki

Determing element namespace prefix
user name
2007-01-06 00:02:36
Hi,

I had sent the message forwarded below to the list a few days ago. I am looking for a way to obtain namespace prefixes in element names.

Any help in this matter would be greatly appreciated.

Thanks,
Aki

---------- Forwarded message ----------
From: Akarsha Kumar < akikumargmail.com">akikumargmail.com>
Date: Jan 2, 2007 3:41 PM
Subject: Determing element namespace prefix
To: xmlgnome.org">xmlgnome.org

Hi,

Is there a straightforward way to determine if an element has a namespace prefix? For the following element:

<myns:Elem> some data </myns:Elem>

I would like to obtain the string "myns:Elem". xmlNode.name simply returns "Elem" and I can't find an obvious way to get to the "myns" part as well.

Thanks,
Aki

Determing element namespace prefix
user name
2007-01-06 01:29:38
Akarsha krishna wrote:
> Hi,
> 
> I had sent the message forwarded below to the list a
few days ago. I am
> looking for a way to obtain namespace prefixes in
element names.
> 
> Any help in this matter would be greatly appreciated.
> 
> Thanks,
> Aki
> 
> ---------- Forwarded message ----------
> From: Akarsha krishna <akikrishnagmail.com>
> Date: Jan 2, 2007 3:41 PM
> Subject: Determing element namespace prefix
> To: xmlgnome.org
> 
> Hi,
> 
> Is there a straightforward way to determine if an
element has a namespace
> prefix? For the following element:
> 
> <myns:Elem> some data </myns:Elem>
> 
> I would like to obtain the string
"myns:Elem". xmlNode.name simply returns
> "Elem" and I can't find an obvious way to get
to the "myns" part as well.
> 
> Thanks,
> Aki


Hi Aki,

I think what you want is xmlNode.ns->prefix.

I access namespaces on attributes, and I get to them as 
xmlNode.properties->ns->prefix.

My code checks that both the ns pointer and the
ns->prefix pointer are 
non-NULL before comparing the prefix string. I don't
remember if that's 
just paranoia or if I discovered cases where NS could be
non-NULL while 
ns->prefix was NULL.

- Rush
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
Determing element namespace prefix
user name
2007-01-06 08:04:59
Hi Rush. Thanks for the response.

I had tried xmlNode.properties-&gt;ns->prefix earlier, but it returns a valid prefix string even for elements/attributes whose names aren't explicitly qualified with a namespace prefix. I'd like to detect the difference between the following two element definitions:

<SomeTopLevelElement xmlns:SomePrefix=&quot;bla">
<MyElement> Some data </MyElement>
&lt;/SomeTopLevelElement>

VS

&lt;SomeTopLevelElement xmlns:SomePrefix=&quot;bla">
<SomePrefix:MyElement> Some data </SomePrefix:MyElement>
&lt;/SomeTopLevelElement>

Thanks,
Aki

On 1/5/07, Rush Manbert < rushmanbert.com">rushmanbert.com> wrote:
Akarsha Kumar wrote:
>; Hi,
>
&gt; I had sent the message forwarded below to the list a few days ago. I am
> looking for a way to obtain namespace prefixes in element names.
>;
> Any help in this matter would be greatly appreciated.
>
&gt; Thanks,
&gt; Aki
>
&gt; ---------- Forwarded message ----------
> From: Akarsha Kumar < akikumargmail.com">akikumargmail.com>
> Date: Jan 2, 2007 3:41 PM
> Subject: Determing element namespace prefix
>; To: xmlgnome.org">xmlgnome.org
>
> Hi,
>
&gt; Is there a straightforward way to determine if an element has a namespace
> prefix? For the following element:
&gt;
> <myns:Elem> some data </myns:Elem>
&gt;
> I would like to obtain the string "myns:Elem". xmlNode.name simply returns
&gt; "Elem" and I can't find an obvious way to get to the "myns" part as well.
>;
> Thanks,
&gt; Aki


Hi Aki,

I think what you want is xmlNode.ns->prefix.

I access namespaces on attributes, and I get to them as
xmlNode.properties->ns->;prefix.

My code checks that both the ns pointer and the ns->prefix pointer are
non-NULL before comparing the prefix string. I don't remember if that's
just paranoia or if I discovered cases where NS could be non-NULL while
ns->prefix was NULL.

- Rush

Determing element namespace prefix
user name
1969-12-31 18:00:00
On Sat, Jan 06, 2007 at 12:04:59AM -0800, Akarsha krishna
wrote:
> Hi Rush. Thanks for the response.
> 
> I had tried xmlNode.properties->ns->prefix
earlier, but it returns a valid
> prefix string even for elements/attributes whose names
aren't explicitly
> qualified with a namespace prefix. I'd like to detect
the difference between
> the following two element definitions:
> 
> <SomeTopLevelElement
xmlns:SomePrefix="bla">
> <MyElement> Some data </MyElement>
> </SomeTopLevelElement>
> 
> VS
> 
> <SomeTopLevelElement
xmlns:SomePrefix="bla">
> <SomePrefix:MyElement> Some data
</SomePrefix:MyElement>
> </SomeTopLevelElement>

  In the first case the namespace for MyElement is NULL at
the C level
(assuming your example is the complete document, for a
fragment a default
namespace may change this).

Daniel


-- 
Red Hat Virtualization group http://redhat.com/v
irtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillardredhat.com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ |
Rpmfind RPM search engine  http://rpmfind.net/
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )