Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: appending a new element to an existing xml file [Thread Next] Re: appending a new element to an existing xml fileTo: 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
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
