Hello Perl Experts.
I am new to perl and seek help with some XML stuff.
My XML document is nested a few levels deep...so I want to use xpath to find the exact element to work with. Then I wish to:
- Modify attribute values
- Add child elements
- Modify text inside existing child elements
I installed ActivePerl v5.10.0 built for MSWin32-x86-multi-thread and used ppm to install XML-DOM and XML-XPATH. However, I don't get how to use them together.
XML::XPATH will allow me to locate the ("mandatory" - refer XML below) element I need ... but probably need XML::DOM to modify the attribute or the elements.
How do I use XPATH and DOM together to perform the mentioned actions ? Any newbie example code snippets (or links to existing posts) will be greatly appreciated.
Here is an XML file similar to what I need:
-
<?xml version="1.0"?>
-
<project>
-
<task>
-
<mode name="default">
-
<prerequisites>
-
<actions>
-
<action name="a1"/>
-
<action name="a2"/>
-
</actions>
-
</prerequisites>
-
<inputs>
-
<item type="applications">App1</item>
-
<item type="applications">App2</item>
-
<item type="applications">App3</item>
-
<item type="document">D1</item>
-
<item type="file">F1</item>
-
<item type="link">L1</item>
-
</inputs>
-
<action name="a1">
-
<step name="S1">Detailed instructions vary for each step</step>
-
<step name="S2">Detailed instructions vary for each step</step>
-
<step name="S3">Detailed instructions vary for each step</step>
-
<step name="S4">Detailed instructions vary for each step</step>
-
<step name="S5">Detailed instructions vary for each step</step>
-
<step name="S5.5" mandatory="true">Detailed instructions vary for each step</step>
-
<step name="S6">Detailed instructions vary for each step</step>
-
</action>
-
<action name="a2">
-
...
-
</action>
-
</mode>
-
<mode name="minimal">
-
...
-
</mode>
-
</task>
-
<task>
-
...
-
</task>
-
</project>
-
-
Thanks in advance,
Parag