#!/usr/bin/perl -w use strict; use XML::LibXML; # NAmespaces my $ONE_ns = 'ONE:'; my $ONE_pfx = 'O'; my $TWO_ns = 'two:IS:a_namEsp'; my $TWO_pfx = 'T'; # The XML Document my $DOC = XML::LibXML->createDocument( "1.0", "UTF-8" ); # Set the root my $root = $DOC->createElement('ABC'); $DOC->setDocumentElement($root); # Establish namespaces $root->setNamespace($ONE_ns, $ONE_pfx, 1); $root->setNamespace($TWO_ns, $TWO_pfx, 0); # Build the document tree my $this = &appendOZ($root); $this = &appendTZ($this); print $DOC->toString(1); sub appendOZ { my $root = shift or die; $root->addNewChild($ONE_ns, 'ZZZ'); return $root; } sub appendTZ { my $root = shift or die; my $this = $root->addNewChild($TWO_ns, 'ZZZ'); &appendOQ($this); return $root; } sub appendOQ { my $root = shift or die; my $this = $root->addNewChild($ONE_ns, 'QWERTY'); &appendTU($this); return $root; } sub appendTU { my $root = shift or die; $root->addNewChild($TWO_ns, 'UIOP'); return $root; }