# Create (local) root node named $rname, the children will be $cname1 and $cname2, $cname1 is in the same namespace as $rname and $cname2 is in a different namespace my $node = XML::LibXML::Element->new($rname); # I want to declare the namespaces and prefixes the children will use. NS_name1 is the namespace of the node itself but it has child nodes that use NS_name2 $node->setNamespace(NS_name1, NS_prefix1, 1); $node->setNamespace(NS_name2, NS_prefix2, 0); # Creating the children. Thi sis not valid code, this is what I want my $cnode1 = XML::LibXML::Element->new($cname1, $NS_name1); my $cnode2 = XML::LibXML::Element->new($cname2, $NS_name2); $node->appendChild($cnode1); $node->appendChild($cnode2); return $node;