. and other ham fist-ed attempts while I grasp at straws. I cannot figure out for the life me what $path I should use in the setNodeText call.

Small program to test one function, like (this should probably be 3 different programs)

#!/usr/bin/perl -- use strict; use warnings; use XML::XPath; Main( @ARGV ); exit( 0 ); sub Main { use XML::XPath; my $xc = XML::XPath->new(xml => SampleXML() ); print "ORIGINAL XML\n"; print $xc->findnodes_as_string('/'), "\n\n"; print "//blocks MATCHES MANY NODES \n"; $xc->setNodeText( '//blocks', ' blah blah ' ); print $xc->findnodes_as_string('/'), "\n\n"; print '//cidr-map-to[@name="AKA Edge"]/blocks MATCHES MANY NODES', + "\n"; $xc->setNodeText( '//cidr-map-to[@name="AKA Edge"]/blocks', ' aha +42 ' ); print $xc->findnodes_as_string('/'), "\n\n"; print '//cidr-map[2]/cidr-map-to/blocks MATCHES ONE NODE', "\n"; $xc->setNodeText( '/Product/cidr-map[2]/cidr-map-to/blocks', ' eur +eka ' ); $xc->setNodeText( '//cidr-map[2]/cidr-map-to/blocks', ' eureka ' ) +; $xc->setNodeText( '//cidr-map[@name="Prod Internal Actual"]/cidr-m +ap-to/blocks', ' eureka ' ); print $xc->findnodes_as_string('/'), "\n\n"; } sub SampleXML { return <<'__XML__'; <?xml version="1.0"?> <Product> <cidr-map default-datacenter="Default Datacenter" name="Internal tes +t"> <cidr-map-to name="AKA Edge"> <blocks>127.0.241.174 127.0.0.181</blocks> </cidr-map-to> </cidr-map> <cidr-map default-datacenter="Default Datacenter" name="Prod Interna +l Actual"> <cidr-map-to name="AKA Edge"> <blocks>127.0.12.1 10.0.0.1 198.168.1.1</blocks> </cidr-map-to> </cidr-map> </Product> __XML__ } __END__ ORIGINAL XML <Product> <cidr-map default-datacenter="Default Datacenter" name="Internal tes +t"> <cidr-map-to name="AKA Edge"> <blocks>127.0.241.174 127.0.0.181</blocks> </cidr-map-to> </cidr-map> <cidr-map default-datacenter="Default Datacenter" name="Prod Interna +l Actual"> <cidr-map-to name="AKA Edge"> <blocks>127.0.12.1 10.0.0.1 198.168.1.1</blocks> </cidr-map-to> </cidr-map> </Product> //blocks MATCHES MANY NODES <Product> <cidr-map default-datacenter="Default Datacenter" name="Internal tes +t"> <cidr-map-to name="AKA Edge"> <blocks> blah blah </blocks> </cidr-map-to> </cidr-map> <cidr-map default-datacenter="Default Datacenter" name="Prod Interna +l Actual"> <cidr-map-to name="AKA Edge"> <blocks> blah blah </blocks> </cidr-map-to> </cidr-map> </Product> //cidr-map-to[@name="AKA Edge"]/blocks MATCHES MANY NODES <Product> <cidr-map default-datacenter="Default Datacenter" name="Internal tes +t"> <cidr-map-to name="AKA Edge"> <blocks> aha 42 </blocks> </cidr-map-to> </cidr-map> <cidr-map default-datacenter="Default Datacenter" name="Prod Interna +l Actual"> <cidr-map-to name="AKA Edge"> <blocks> aha 42 </blocks> </cidr-map-to> </cidr-map> </Product> //cidr-map[2]/cidr-map-to/blocks MATCHES ONE NODE <Product> <cidr-map default-datacenter="Default Datacenter" name="Internal tes +t"> <cidr-map-to name="AKA Edge"> <blocks> aha 42 </blocks> </cidr-map-to> </cidr-map> <cidr-map default-datacenter="Default Datacenter" name="Prod Interna +l Actual"> <cidr-map-to name="AKA Edge"> <blocks> eureka </blocks> </cidr-map-to> </cidr-map> </Product>
Read http://w3schools.com/xpath/default.asp for gentle introduction to xpath.

In reply to Re: Trouble using setNodeText() by Anonymous Monk
in thread Trouble using setNodeText() by Plankton

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.