Discussion on:
View:
Show:
Do you have a preferred method? Do you use PHP? Something else?
i liekd this alot been doing it for hour r so now having a mess around with it, just one thing is there anyway to format the source code output so its all neat in tree like browser view? thanks Chris
hi
this is nice article and very help full.
i need small help on this.
i am doing similar project to this.
what i need is php should add data to next line of the xml format.
write now its not adding to next line. it is deleting previous value and adding new value.
any my php code is here:-
$dom = new domDocument("1.0");
$dom->load('contacts.xml');
$root = $dom->createElement("content");
$dom->appendChild($root);
$dom->formatOutput=true;
$item = $dom->createElement("contents");
$root->appendChild($item);
$price = $dom->createAttribute("name");
$item->appendChild($price);
$priceValue = $dom->createTextNode($_POST['name']);
$price->appendChild($priceValue);
$address = $dom->createAttribute("comments");
$item->appendChild($address);
$priceValue = $dom->createTextNode($_POST['comments']);
$address->appendChild($priceValue);
$dom->save("contacts.xml");
$order = $dom->save("contacts.xml");
xml out put should be like this
please help me on this php code if you can. I'll be very thank full to you.
shankar
this is nice article and very help full.
i need small help on this.
i am doing similar project to this.
what i need is php should add data to next line of the xml format.
write now its not adding to next line. it is deleting previous value and adding new value.
any my php code is here:-
$dom = new domDocument("1.0");
$dom->load('contacts.xml');
$root = $dom->createElement("content");
$dom->appendChild($root);
$dom->formatOutput=true;
$item = $dom->createElement("contents");
$root->appendChild($item);
$price = $dom->createAttribute("name");
$item->appendChild($price);
$priceValue = $dom->createTextNode($_POST['name']);
$price->appendChild($priceValue);
$address = $dom->createAttribute("comments");
$item->appendChild($address);
$priceValue = $dom->createTextNode($_POST['comments']);
$address->appendChild($priceValue);
$dom->save("contacts.xml");
$order = $dom->save("contacts.xml");
xml out put should be like this
please help me on this php code if you can. I'll be very thank full to you.
shankar
This guide is amazing, now, is there anyway to "organize" the xml in the correct format? it is all in one line without indent nor nothing and should be in several lines, with indent.
i got an erro when i upload to my server linux, this are the ERROR that send me:
[error] PHP Warning: domdocument(): Start
tag expected, '<' not found\n in
/usr/local/apache2/nueva/universidad/comunicacion/tv-uaeh/generar.php on
line 17
[Tue Oct 7 15:40:09 2008] [error] PHP Fatal error: Call to undefined
function: createelement() in
/usr/local/apache2/nueva/universidad/comunicacion/tv-uaeh/generar.php on
line 24
Any help???
aliensurvive@hotmail.com
[error] PHP Warning: domdocument(): Start
tag expected, '<' not found\n in
/usr/local/apache2/nueva/universidad/comunicacion/tv-uaeh/generar.php on
line 17
[Tue Oct 7 15:40:09 2008] [error] PHP Fatal error: Call to undefined
function: createelement() in
/usr/local/apache2/nueva/universidad/comunicacion/tv-uaeh/generar.php on
line 24
Any help???
aliensurvive@hotmail.com
Very good tutorial, thank you solved me a lot of time and coding
Hi i m trying to generate a xml file from my databse..
The script is given below
if (mysql_num_rows($result) > 0)
{
// Create the DomDocument object.
$doc = new_xmldoc("1.0");
// Add root node.
$root = $doc->add_root("AnswerSet title ='$n'");
// Iterate through result set.
while(list($mine,$yours) = mysql_fetch_row($result))
{
// Create item node.
$rec = $root->new_child("Answername","");
$rec->set_attribute("Name","Mine");
$rec = $root->new_child("TFvalue","$mine");
$rec = $root->new_child("TFvalue","$yours");
}
echo $doc->dumpmem(true,'UTF-8');
$xml_string = $doc->dump_mem(true,'UTF-8');
$fh = fopen("c:/testdir/file.xml","a");
fwrite($fh,$xml_string);
fclose($fh);
}
By using this script i m able to get the XMl file but the XMl file that is getting generated is not in the corret format..
Th Answer tag should be closed after printing the value of $yours but the Answer tag is getting closed early..
below is the Xml that is geting produced by using this code
India Country
New York
India
pakistan
And i want the Xml to be produced like this(Shown below)
India Country
New York
India
pakistan
Kindly note the change in the positon of the
The script is given below
if (mysql_num_rows($result) > 0)
{
// Create the DomDocument object.
$doc = new_xmldoc("1.0");
// Add root node.
$root = $doc->add_root("AnswerSet title ='$n'");
// Iterate through result set.
while(list($mine,$yours) = mysql_fetch_row($result))
{
// Create item node.
$rec = $root->new_child("Answername","");
$rec->set_attribute("Name","Mine");
$rec = $root->new_child("TFvalue","$mine");
$rec = $root->new_child("TFvalue","$yours");
}
echo $doc->dumpmem(true,'UTF-8');
$xml_string = $doc->dump_mem(true,'UTF-8');
$fh = fopen("c:/testdir/file.xml","a");
fwrite($fh,$xml_string);
fclose($fh);
}
By using this script i m able to get the XMl file but the XMl file that is getting generated is not in the corret format..
Th Answer tag should be closed after printing the value of $yours but the Answer tag is getting closed early..
below is the Xml that is geting produced by using this code
India Country
New York
India
pakistan
And i want the Xml to be produced like this(Shown below)
India Country
New York
India
pakistan
Kindly note the change in the positon of the
i posted a question earlier but the website(techrepublic) is not displaying the XMl with the tags..
Once you have enabled the XSL extension, you can use XSL functions to transform XML into HTML or another XML or a variety of other formats. The following figure depicts the general steps performed by a PHP/Oracle application that generates an Affiliate Programs and HTML page with PHP, based on the result set retrieved from the database.
you can format the xml output by adding $domdocument->formatoutput = true;
here $domdocument is domdocument object.
here $domdocument is domdocument object.
This tutorial was extremely well written and easy to follow. I now have a better understanding on how the DOM writes XML Structures.
Thanks so much. Any tutorials about how to read in a xml data from a file, add to the root and then rewrite it as a new xml file?
Thanks so much. Any tutorials about how to read in a xml data from a file, add to the root and then rewrite it as a new xml file?
Great article!
What if the xml is an svg file and how can I dipslay the .svg on the fly instead of saving it to a file.
I mean if the type ="image/svg+xml", how can we display the svg image to the browser without saving it to a file?
Thanks
What if the xml is an svg file and how can I dipslay the .svg on the fly instead of saving it to a file.
I mean if the type ="image/svg+xml", how can we display the svg image to the browser without saving it to a file?
Thanks
The answer could be better if an explanation of 'editing and delete' have been added. Does anyone know how? Or a link?
Anyone knows a better way: http://www.fluidbyte.net/php-and-xml-using-simplexml ?
- Keyboard Shortcuts:
- Prev
- Next
- Toggle









































