in reply to Edit XML through XML Compile

It would help if you could post a short, representative sample of your input, desired output, and the code you are using. See How do I post a question effectively?

Replies are listed 'Best First'.
Re^2: Edit XML through XML Compile
by chenino (Acolyte) on Dec 19, 2014 at 16:04 UTC
    Well i know generally a code example is helpfull, but i thought in this case its a pretty General question. Anyhow, I will give you some examples of what i am doing at the Moment. given is a Schema like :
    -data -properties (List of properties in here) -suites -tests
    Up to now i got my code writing the properties.
    $schema->template('PERL', $type); #warn $schema->template('PERL', $type); my $doc = XML::LibXML::Document->new('1.0', 'UTF-8'); my $write = $schema->compile(WRITER => $type, use_default_namespace +=> 1); my %hash; #some filling of the hash with values my $xml = $write->($doc, $hash); $doc->setDocumentElement($xml);
    So the first part of my XML File is generated. Later on, in a completely different part of the program, tests have to be written into the second section. Those tests have to comply the Schema in the xsd file. So i have to reopen the saved XML file from the code above and insert some new tags in it, at specific Points (every test has to go into a specific Suite, so there is more than one Suite) Writing a new hash and doing
    my $xml = $write->($doc, $hash); $doc->setDocumentElement($xml);
    again, does not work out. I need to reopen, search a node and insert children. This was easy possible with XML Twig, but as said i can only use above mentioned packages. Was this enough code or do you Need more explaning?

        Well, maybe does not work out wasn't the right choice of words, i am sorry for this.

        Yes, my question is as General as you answered it, but you seemed to got me wrong in one point.

        I have read overmeers article before i opened my thread. (I read the other two links previously too)

        In the section about writing, he explains how to insert a node in an existing file, DWIM style. Thats what i want to do, as working in the hashes seems to unreliable for me.

        Unfortunately, i haven't got XML::Compiler::Cache for use. So my question was about if there is any way to to it in this style but with only the modules given in my first post and without Messing aroung within the hashes. Even if there would be an easy way to get my XML File into an LibXML-Document and search for parents and add children in this would be enough for me, i think.

        Thas why i was asking for if there is any possibility in XML Compile to edit items in a style like in LibXML::Documents or XML:Twig