Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^4: Perl XML

by ramya2005 (Scribe)
on Aug 10, 2005 at 00:20 UTC ( [id://482471]=note: print w/replies, xml ) Need Help??


in reply to Re^3: PERL XML
in thread Perl XML

Thanks for your response. I would appreciate if you can provide me with a more specific example or code snippet using XMl::Twig

Replies are listed 'Best First'.
Re^5: Perl XML
by Tanktalus (Canon) on Aug 10, 2005 at 02:15 UTC

    I'm not going to write the code for you, but I did have a similar requirement that a particular element could exist prior to me trying to insert it. So I wrote a quick "xml_child" routine that would look for a specific element, return it if it were there, but if it weren't, it would create it, then return that. You can also provide parms for setting some stuff if the element is being created, or other parms for setting stuff whether it's being created or updated.

    Note that this was my first time using XML of any type, let alone XML::Twig, so be gentle with any criticisms ;-)

    Example usage:

    $child = xml_child(parent => $elt, child => 'built', action => 'after' +, relto => $prev_child, def_text => '19700101 000000.000-0000'); $prev_child = $child; $child = xml_child(parent => $elt, child => 'sha +reable', action => 'after', relto => $prev_child, override_text => 't +rue');
    Here I'm creating a series of elements, and even specifying order by the order I insert (although if it's already there out of order, then I won't correct the order). I also have some default text which won't change anything that is already present but I have some override text that says that I don't care what the XML owner says, I'm changing the shareable element to be "true".

    This is probably adaptable to what you sound like you need.

    If you're wondering why the lack of whitespace in the example - it's because I have about 30 of these... and I just needed to get it done - after it was done, it was more important to be able to pgup/pgdn through past these constants than to make it readable. ;-> If I were doing it again, I'd find a way to put this data somewhere else and loop through it.

Re^5: Perl XML
by prasadbabu (Prior) on Aug 10, 2005 at 01:07 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://482471]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 19:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found