L
Larry Sulky
I have this XML data:
<doc>
<title>Aaa</title>
<para>Ppp</para>
<section type="baz">
<title>Xxx</title>
<para>Qqq</para>
<section>
<title>Mmm</title>
</section>
<title>Yyy</title>
<para>Rrr</para>
</section>
</doc>
Notice that 'doc/section' has two 'title' children. I need to split
'doc/section' in two:
<doc>
<title>Aaa</title>
<para>Ppp</para>
<section type="baz">
<title>Xxx</title>
<para>Qqq</para>
<section>
<title>Mmm</title>
</section>
</section><!-- Insert this -->
<section type="baz"><!-- And this -->
<title>Yyy</title>
<para>Rrr</para>
</section>
</doc>
I need to retain any attributes on the parent of 'title' ('section' in
this example), and I need to handle the occurrence of multiple 'title'
elements within a single parent no matter where they occur. The parent
is not necessarily 'section' and the issue can occur at any hierarchic
level. Extra credit: do NOT split if the 'title' elements are
adjacent; just join them into one element.
I would like a way to interrogate the Xpath of each 'title' and if I
see an identical path except for the final index -- for example, 'doc/
section[1]/title[1]' and 'doc/section[1]/title[2]', be able to throw
the 'section[1]' node into a variable and process it there. What's the
simplest XML package for Perl to do this? Is there another approach
(other than 'title' interrogation) someone can recommend?
Thanks!
<doc>
<title>Aaa</title>
<para>Ppp</para>
<section type="baz">
<title>Xxx</title>
<para>Qqq</para>
<section>
<title>Mmm</title>
</section>
<title>Yyy</title>
<para>Rrr</para>
</section>
</doc>
Notice that 'doc/section' has two 'title' children. I need to split
'doc/section' in two:
<doc>
<title>Aaa</title>
<para>Ppp</para>
<section type="baz">
<title>Xxx</title>
<para>Qqq</para>
<section>
<title>Mmm</title>
</section>
</section><!-- Insert this -->
<section type="baz"><!-- And this -->
<title>Yyy</title>
<para>Rrr</para>
</section>
</doc>
I need to retain any attributes on the parent of 'title' ('section' in
this example), and I need to handle the occurrence of multiple 'title'
elements within a single parent no matter where they occur. The parent
is not necessarily 'section' and the issue can occur at any hierarchic
level. Extra credit: do NOT split if the 'title' elements are
adjacent; just join them into one element.
I would like a way to interrogate the Xpath of each 'title' and if I
see an identical path except for the final index -- for example, 'doc/
section[1]/title[1]' and 'doc/section[1]/title[2]', be able to throw
the 'section[1]' node into a variable and process it there. What's the
simplest XML package for Perl to do this? Is there another approach
(other than 'title' interrogation) someone can recommend?
Thanks!