Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: appending a new element to an existing xml file

From: ofuuzo1@-----.--
To: NULL
Date: 3/7/2008 3:30:00 AM
On 5 Mar, 14:56, J=FCrgen Kahrs <Juergen.KahrsDELETET...@vr-web.de>
wrote:
> ofuu...@yahoo.no schrieb:
>
>
>
> > On 5 Mar, 14:23, ofuu...@yahoo.no wrote:
> >> Hi,
> >> Is there anyway I can append a new element to an existing xml without
> >> first loading the existing file into a variable, adding the new
> >> element into the variable and saving it by overwriting the existing
> >> file name?
>
> >> Thanks
> >>Ofuuzo
>
> > To smplify my question.
> > I have nth xml files and I want to put all of them together in one xml
> > file called new.xml. How can I do it?
>
> > Example
>
> > 1.xml
> > <head>
> >    <title>Test1</title>
> > ....
> > </head>
>
> > 2.xml
> > <head>
> >    <title>Test2</title>
> > ....
> > </head>
>
> > n.xml
> > 1.xml
> > <head>
> >    <title>Test nth</title>
> > ....
> > </head>
>
> Many others have asked this before.
> The official anwer is that you cant just
> concatenate files because XML data is allowed
> to have one root element only.
>
> Some parsers seem to tolerate XML files that
> consist of a sequence of XML root elements.
> But remember that these files are not well-
> formed XML files anymore, although the look so.

Thanks.  The new xml file does not need a new root element. All what I
want is to transform each xml file and store all of them in a new xml
file.  I need help on how I can store the new.xml in a variable,
concatenate "new.xml" and "nth_old.xml" and then store it back as
"new.xml". This is what I have done:

<?php

for ($i =3D 0; $i <  50) {

 /* load the xml file and stylesheet as dom documents */
 $xsl =3D new DomDocument();
 $xsl->load("transform.xsl");

 $old =3D  $i."old.xml";

 $inputdom =3D new DomDocument();
 $inputdom->load($old);

  /* create the processor and import the stylesheet */
 $proc =3D new XsltProcessor();
 $xsl =3D $proc->importStylesheet($xsl);

 /* transform and output the xml document */
 $newdom =3D $proc->transformToDoc($inputdom);

 print $newdom->saveXML();
 print $newdom->save("new.xml");
}
?>

Ofuuzo


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent