ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
Re: XML::LibXML - appending children and finding them again
by Christopher Pryce other posts by this author
Jan 18 2005 3:02PM messages near this date
view in the new Beta List Site
Re: Seg Faults Using HTML::Tidy -- Any Alternatives? | Re: XML::LibXML - appending children and finding them again
& XSLT On Jan 18, 2005, at 2:05 PM, perl-xml-request@[...].com 
wrote:

>  Don't mix NS and non NS createElement calls.
>  Changing your non NS call by
> 
>  my $docProps = $dom->
>  createElementNS('urn:schemas-microsoft-com:office:office', 		
>  'o:DocumentProperties');
> 
>  fixes the problem.
>  (A little my $o = 'urn:...'; might help keeping you code tidy).

Thank you. The previous posts helped me realize the errors. I was not 
creating the objects in the namespace, I was simply making them with 
the prefix.

So now I use the following code, which seems to work. Is the 
addNewChild($NS, $name) the correct usage? Or will it bite me later?

use strict;
use XML::LibXML;

my $dom = XML::LibXML::Document-> new();

# constants
my $NSw = 'http://schemas.microsoft.com/office/word/2003/wordml';
my $NSo = 'urn:schemas-microsoft-com:office:office';

# create the root element w:wordDocument
my $root =  $dom->  createElementNS( $NSw,'w:wordDocument');

# add the additional namespace
$root->  setNamespace($NSo, 'o', 0 );
$root->  setAttribute('xml:space', "preserve");

my $pi = $dom-> createPI('mso-application', 'progid="Word.Document"');
$dom->  appendChild( $pi );

$dom->  setDocumentElement( $root );

# add the document properties
my $dp = $root-> addNewChild( $NSo, 'DocumentProperties');

# set the rest of the properties here

# add the body element
my $body = $root-> addNewChild( $NSw, 'body');

## Yields, as expected ..
<?xml version="1.0"?> 
<?mso-application progid="Word.Document"?> 
<w:wordDocument 
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" 
xmlns:o="urn:schemas-microsoft-com:office:office" xml:space="preserve"> 
	<o:DocumentProperties /> 
	<w:body /> 
</w:wordDocument> 




_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Christopher Pryce
Petr Pajas
Christopher Pryce
Petr Pajas

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved