AndyH has asked for the wisdom of the Perl Monks concerning the following question:

Anyone got experience with XML-mini?

I have got the thing doing changing attribute values, re-ordering elements and writing back the result but I don't seem to be able to figure out (understand) how to insert a new element or remove an existing element and write back the modified result. The example code only covers parsing a file or generating a new file, not modifying and writing back.

All hints/tips gratefully received. I'd prefer to use XML-Mini if possible as it doesn't require loads of other modules to work.

AndyH.

Replies are listed 'Best First'.
Re: Altering values in XML-mini
by PodMaster (Abbot) on Mar 31, 2003 at 12:52 UTC
    The documentation seems perfectly clear to me ... here's an example
    use XML::Mini::Document; my $newDoc = XML::Mini::Document->new(); my $root = $newDoc->getRoot(); my $header = $root->header('xml'); # set the header $header->attribute('version', '1.0'); my $kid = $root->createChild('foo'); $kid->text("Yes, I am a kid"); $root->createChild('foo')->text('Me Too'); print $newDoc->toString(); __END__ <?xml version="1.0"?> <foo> Yes, I am a kid </foo> <foo> Me Too </foo>
    Holler if this ain't clear for you, but be sure to provide more context (and show that you've read the documentation, cause the documentation is thorough).

    update: I can see now (through ESP) how you might be confused. The text methods APPENDS (appends) values to an element. The only way to get at the XML::Mini::Node's is to cheat and look at an XML::Mini::Element's _children attribute. The XML::Mini API is thus flawed and for no apparent reason.

    update: I've added this to Feature Requests.
    [ 712722 ] missing a XML::Mini::Element method to set text


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
    ** The Third rule of perl club is a statement of fact: pod is sexy.

      update: I can see now (through ESP) how you might be confused. The text methods APPENDS (appends) values to an element. The only way to get at the XML::Mini::Node's is to cheat and look at an XML::Mini::Element's _children attribute.

      Which is what I have been doing for the re-ordering and attribute changing. I just haven't figured out the appropriate wizardry to do remove an element or add an element.

      Also, I'm not clear if the code you posted is how you want XML::Mini to work or if that's the _children workaround I'm looking for ...

      A.

Re: Altering values in XML-mini
by nothingmuch (Priest) on Mar 31, 2003 at 12:51 UTC
    Due to the nature of XML files being contiguos it's hard to solve the problem of editing without rewriting everything from the edit point right down to the end of the document.

    I'd suggest simply rewriting the document from scratch, and replacing the old version with the new.

    If efficiency bothers you then perhaps a different module may be of use after all. It doesn't look as though XML::Mini is capable of doing this, although i haven't gone through all the source code of the modules yet.

    Update:I'm sorry, i thought you ment something else... please see PodMaster's reply for what you really wanted.

    -nuffin
    zz zZ Z Z #!perl