use strict; use XML::LibXML; my $ns = 'http://www.example.com'; my $doc = XML::LibXML::Document->new; $doc->setDocumentElement($doc->createElementNS($ns, 'q:one')); my $elem_two = $doc->documentElement->appendChild($doc->createElementNS($ns, 'q:two')); my $elem_three = $doc->documentElement->appendChild($doc->createElement('q:three')); warn $doc->toString(1); # look at the namespace in DOM warn 'namespace of q:two is ', $elem_two->namespaceURI, "\n"; warn 'namespace of q:three is ', $elem_three->namespaceURI, "\n"; # via findnodes warn 'q:* nodes are ', join (',', map {$_->nodeName} $doc->documentElement->findnodes('//q:*')), "\n"; #### namespace of q:two is http://www.example.com namespace of q:three is q:* nodes are q:one,q:two