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

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!

Replies are listed 'Best First'.
Re^5: LibXML Namespace issue
by choroba (Cardinal) on Jan 03, 2014 at 13:39 UTC
    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"; }
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      I understand now. The code you posted does what I have been doing. It goes directly to the <check-content> node and pulls that data. If there is more than one instance of <check-content> under <Rule> then they are pushed into 2 spaces in the array. I am trying to pull the node(s) <check-content> and if there is more than one, combine them into one string. I need to be able to pull the section <Rule> </Rule> and then parse that section to pull the <check-content> nodes. That is the only way I could think of to pull those nodes and then combine them before pushing the data into an array. I can pull directly from the <check-content> node using the default namespace without issue, but if I back up to "Rule" in order to grab all instances of <check-content> under that Rule it includes the <reference> section that has a different namespace and bombs out. I need some way to tell it to pull the node with the other (dc) namespace also, or to ignore it and pull everything that has the default namespace.