in reply to Re: LibXML Namespace issue
in thread LibXML Namespace issue

The XML does have the namespace defined. "xmlns:dc="http://purl.org/dc/elements/1.1/" The problem I am having is I need to grab a chunk of the XML and it contains the default namespace and the above namespace. I can use the default like //x:Group/x:rule etc, but under rule is also the "dc" namespace. I either need to be able to grab that part also, or tell LibXML to ignore that section and give me everything else. The portion that is using the "dc" namespace is of no interest to me. I hope this makes sense.

Replies are listed 'Best First'.
Re^3: LibXML Namespace issue
by choroba (Cardinal) on Jan 03, 2014 at 12:17 UTC
    An example would probably help more. Anyway, have you tried the wildcards in XPath (Rule/*/text()) or the local-name() function?
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      I do have an example in the original post. Can you not see it? Did I somehow not post it correctly? I am using a function like this:  for $Check ( $xc1->findvalue('//x:Rule') ) {

      If you cannot see the code in my original post let me know. I will repost the information. I have not tried the XPath (Rule/*/text()) or the local-name() function? Can you give me an example of how I would modify my code to try those? Thanks!

        I can see the code and data samples, but I was not able to understand what exactly you are trying to achieve. For example, the following script processes both the input files (enhanced by the namespace declarations). I do not see any issue with the namespace - what exactly do you want to do with the elements in the dc namespace?
        #!/usr/bin/perl use warnings; use strict; use XML::LibXML; my $xpc = 'XML::LibXML::XPathContext'->new; $xpc->registerNs(x => 'http://checklists.nist.gov/xccdf/1.1'); $xpc->registerNs(dc => 'http://purl.org/dc/elements/1.1'); for my $file (glob '*.xml') { print "# $file:\n"; my $string; my $xml = 'XML::LibXML'->load_xml(location => $file); $string .= $_ for $xpc->findnodes('/x:Group/x:Rule/x:check/x:check +-content/text()', $xml->documentElement); print "$string\n"; }
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ