Hi Monks,

I have an XML file with following dummy data. Seeking help on how to remove an element from XML file using XML::LibXML.

Condition to remove element

If value of uid is equal to input value then remove corresponding document element.

<searchresult> <document id="3404"> <uid>16b3</uid> <title><![CDATA[Title1]]></title> <author><![CDATA[Author1]]></author> <date><![CDATA[2010]]></date> <source><![CDATA[Source1]]></source> <volume><![CDATA[1]]></volume> <issue><![CDATA[1]]></issue> <snippet><![CDATA[Snippet]]></snippet> <abstract_url><![CDATA[http://yourhost.com/ar1]]></abstract_url> <fulltext_url><![CDATA[http://yourhost.com/ft1]]></fulltext_url> <resource> <longname><![CDATA[Name1]]></longname> </resource> <nativesearch_url><![CDATA[http://yourhost.com/n1]]></nativesearch_url +> </document> <document id="3404"> <uid>3cdd</uid> <title><![CDATA[Title2]]></title> <author><![CDATA[Author2]]></author> <date><![CDATA[2010]]></date> <source><![CDATA[Source2]]></source> <volume><![CDATA[2]]></volume> <issue><![CDATA[2]]></issue> <snippet><![CDATA[Snippet]]></snippet> <abstract_url><![CDATA[http://yourhost.com/ar1]]></abstract_url> <fulltext_url><![CDATA[http://yourhost.com/ft1]]></fulltext_url> <resource> <longname><![CDATA[Name1]]></longname> </resource> <nativesearch_url><![CDATA[http://yourhost.com/n1]]></nativesearch_url +> </document> <document id="3404"> <uid>446d</uid> <title><![CDATA[Title1]]></title> <author><![CDATA[Author1]]></author> <date><![CDATA[2010]]></date> <source><![CDATA[Source1]]></source> <volume><![CDATA[1]]></volume> <issue><![CDATA[1]]></issue> <snippet><![CDATA[Snippet]]></snippet> <abstract_url><![CDATA[http://yourhost.com/ar1]]></abstract_url> <fulltext_url><![CDATA[http://yourhost.com/ft1]]></fulltext_url> <resource> <longname><![CDATA[Name1]]></longname> </resource> <nativesearch_url><![CDATA[http://yourhost.com/n1]]></nativesearch_url +> </document> </searchresult>

Any help would be greatly appreciated.

Thanks

In reply to Deleting XML element using XML::LibXML by shanu_040

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.