Click here to get back home

namespace declarations in LibXML

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
namespace declarations in LibXML edward.kawas 04-15-2006
Posted by edward.kawas on April 15, 2006, 12:48 am
Please log in for more thread options


Hi,

I am using LibXML to create an xml document. I am also using
namespaces.

The problem that i am running into is that the document that i am
creating has the namespace declaration at each element.

For instance,

<foo:A xmlns:foo="http://www.www.com/foo">
<foo:B xmlns:foo="http://www.www.com/foo"> blah blah blab </foo:B>
<foo:C xmlns:foo="http://www.www.com/foo"> blah blah blab </foo:C>
</foo:A>

And I want the following:
<foo:A xmlns:foo="http://www.www.com/foo">
<foo:B> blah blah blab </foo:B>
<foo:C> blah blah blab </foo:C>
</foo:A>

How can i achieve this?

Thanks.

Ed


Posted by Steven N. Hirsch on April 15, 2006, 1:47 pm
Please log in for more thread options


edward.kawas@gmail.com wrote:
> Hi,
>
> I am using LibXML to create an xml document. I am also using
> namespaces.
>
> The problem that i am running into is that the document that i am
> creating has the namespace declaration at each element.
>
> For instance,
>
> <foo:A xmlns:foo="http://www.www.com/foo">
> <foo:B xmlns:foo="http://www.www.com/foo"> blah blah blab </foo:B>
> <foo:C xmlns:foo="http://www.www.com/foo"> blah blah blab </foo:C>
> </foo:A>
>
> And I want the following:
> <foo:A xmlns:foo="http://www.www.com/foo">
> <foo:B> blah blah blab </foo:B>
> <foo:C> blah blah blab </foo:C>
> </foo:A>
>
> How can i achieve this?

Just a WAG, but try something like this on the top element before
writing it out:

my $attr = $dom->createAttributeNS( '', 'dummy', '' );
$dom->getDocumentElement()->setAttributeNodeNS( $attr );

I solved a slightly different namespace-related problem by doing so.

Steve

Posted by edward.kawas on April 15, 2006, 4:08 pm
Please log in for more thread options


Hi Steve, that didnt help.

Thanks.


Posted by Brian McCauley on April 18, 2006, 2:21 pm
Please log in for more thread options



edward.kawas@gmail.com wrote:
> Hi,
>
> I am using LibXML to create an xml document. I am also using
> namespaces.
>
> The problem that i am running into is that the document that i am
> creating has the namespace declaration at each element.
>
> For instance,
>
> <foo:A xmlns:foo="http://www.www.com/foo">
> <foo:B xmlns:foo="http://www.www.com/foo"> blah blah blab </foo:B>
> <foo:C xmlns:foo="http://www.www.com/foo"> blah blah blab </foo:C>
> </foo:A>
>
> And I want the following:
> <foo:A xmlns:foo="http://www.www.com/foo">
> <foo:B> blah blah blab </foo:B>
> <foo:C> blah blah blab </foo:C>
> </foo:A>

Why do you care? The two are semantically identical. Are you concened
about file size or the aesthetic appeal of the XML source?

> How can i achieve this?

I've seen similar problems myself. Perhaps if you posted a _minimal_
but _complete_ stript that manifests the problem[1] I could advise how
to work around it.

[1] This and much other advice can be found in the posting guidelines.


Posted by edward.kawas on April 19, 2006, 7:51 pm
Please log in for more thread options


Hi,

I realize that they are semantically identical.

Some example code:

use XML::LibXML;
        my $root =
         XML::LibXML::Element->new( "A" );
        $root->setNamespace( "http://www.www.com/foo", "foo" );

        my $b =
         XML::LibXML::Element->new( "B" );
        $b->setNamespace( "http://www.www.com/foo", "foo" );
        $b->setAttributeNS( "http://www.www.com/foo", "foo", "name");
        $root->appendChild($b);

        my $c =
         XML::LibXML::Element->new( "C" );
        $c->setNamespace( "http://www.www.com/foo", "foo" );
        $c->setAttributeNS( "http://www.www.com/foo", "foo", "name");
        $root->appendChild($c);

print $root->toString(2);

Thanks.

Ed


Similar ThreadsPosted
LibXML "Undefined namespace prefix" July 2, 2007, 5:42 pm
Possible bug in XML:LibXML December 16, 2007, 6:22 am
LibXML and DTD's July 5, 2007, 1:26 pm
Questions about XML:LibXML December 16, 2007, 6:22 am
data structure from XML::LibXML October 6, 2004, 6:22 pm
compile problems with XML::LibXML December 22, 2004, 5:41 pm
problems with installation of XML::LibXML June 7, 2005, 10:30 am
XML::LibXML and getting data from elements/nodes October 26, 2004, 7:50 pm
SGF namespace August 1, 2005, 5:18 pm
New Namespace? January 27, 2007, 3:00 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap