Can you also please give me some example of how to use regex and replace existing node with new node structure and values.ThanksVinit
#!/usr/bin/perluse strict;use warnings;my $xml_string = do {local $/; <DATA> };my $new_xml = qq(<new_stuff> <regex_hacking>is fun in perl</regex_hacking> <this>can be simpler than XML parsing sometimges</this></new_stuff>);$xml_string =~ s|<replace_me>.*</replace_me>|$new_xml|sm;print $xml_string;exit 0;__DATA__<record> <something> <an_item>of some sort</an_item> <another_item>of another sort</another_item> <replace_me>completely</replace_me> </something></record>
In "XML-like" substitution it is safer to do "non-greedy" Match. Your version *may* replace too much if there areseveral "replace_me" Tags - which is not the case in the sample $xml_string =~ s|<replace_me>.*?</replace_me>|$new_xml|sm;(Without 'g' modifier that'll get the first or the only one)
I have replaced existing XML with new XML, but when I open a new DCR, it doesnt show values for some existing fields
I have replaced existing XML with new XML, but when I open a new DCR, it doesnt show values for some existing fieldsFor e.gIn DCR, I have a Text field -- object_desc_itemIn DCR XML, values is present.. but it is not reflected in DCR field.Please find attached the code(line 204-221) and Modified and Old XML file.Thanks Vinit
... <object_desc_item> <p><strong>Can I apply directly to one of Monitor's business units?</strong><br /> ... </object_desc_item>...
... <object_desc_item> <p> <strong>Can I apply directly to one of Monitor's business units?</strong> ... </object_desc_item>...
When you're re-inserting text, especially for textarea fields, you have to make sure that the contents of the text are re-entitized (for lack of a real word). For instance (code formatted with indenting), in the OLD DCR I see:... <object_desc_item> <p><strong>Can I apply directly to one of Monitor's business units?</strong><br /> ... </object_desc_item>...but in the NEW DCR I see:... <object_desc_item> <p> <strong>Can I apply directly to one of Monitor's business units?</strong> ... </object_desc_item>...Thus, in the new DCR, the structure has changed because there are now 'p' and 'strong' containers, etc.Take a look at perldoc HTML::Entities for help on resolving this.(PS: Thanks Boris for the non-greedy fix, I neglected to think of that at the time I threw together a quick demo)
I am still strugling to get exact info.. can please someone help..