corillo181 Posted September 3, 2007 Share Posted September 3, 2007 alright so i got a xml file that has the fallowing. <?xml version="1.0" encoding="utf-8"?> <artists> </artists> than i have a php code that add artists to this file. it looks like this. <?php include_once($_SERVER['DOCUMENT_ROOT'].'/include/db.php'); $dom = new DomDocument(); $dom->load("test.xml"); $xp = new domxpath($dom); $dom->formatOutput = true; $item = $dom->createElement("artist"); $title = $dom->createElement("name"); $link = $dom->createElement("image"); $titletext = $dom->createTextNode("JUly el champ"); $linkpath = $dom->createTextNode("filepathtoimage.jpg"); $title->appendChild($titletext); $link->appendChild($linkpath); $item->appendChild($title); $item->appendChild($link); $item->setAttribute("id", "2"); $dom->documentElement->appendChild($item); $dom->save('test.xml'); ?> there is no problem with the code the problem is with the xml format. i want it to look <?xml version="1.0"?> <artists> <artist id="2"> <name>JUly el champ</name> <image>filepathtoimage.jpg</image> </artist> </artists> but it looks like this <?xml version="1.0"?> <artists> <artist id="2"><name>JUly el champ</name><image>filepathtoimage.jpg</image></artist></artists> Quote Link to comment Share on other sites More sharing options...
d22552000 Posted September 3, 2007 Share Posted September 3, 2007 uh output \n after every dom object? that should make the newlines.. but as far as "name" im not sure. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted September 3, 2007 Share Posted September 3, 2007 Does it really matter? It's just whitespace. If you want it like that, then you can use tidy though. uh output \n after every dom object? that should make the newlines.. but as far as "name" im not sure. You do apparently not understand the code he posted. Quote Link to comment Share on other sites More sharing options...
Azu Posted September 3, 2007 Share Posted September 3, 2007 Maybe turn the newlines into <br/> and the spaces into nsbp;? Works in XHTML, not sure if it works in pure XML but it should.. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted September 3, 2007 Author Share Posted September 3, 2007 oh so danielo if it was oyu you wouldn't pay mind to the format? Quote Link to comment Share on other sites More sharing options...
d22552000 Posted September 3, 2007 Share Posted September 3, 2007 lol im used to XML having a hi-erachal format. <xml> <group> <phrase> <value> </value> </phrase> </group> </xml> lol Quote Link to comment Share on other sites More sharing options...
corillo181 Posted September 3, 2007 Author Share Posted September 3, 2007 i don't know what the problem is because they got a property that makes xml look formated after you have inserted something i have it on my code is $dom->formartOutput = yes; this works with the first insert and no more after it. Quote Link to comment Share on other sites More sharing options...
d22552000 Posted September 3, 2007 Share Posted September 3, 2007 lol if its works use it. use it befroe each dom call? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted September 3, 2007 Share Posted September 3, 2007 oh so danielo if it was oyu you wouldn't pay mind to the format? Not really, as long as it's valid syntax, but if you can do what corillo181 says (I didn't bother to check), then you might as well do so. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted September 3, 2007 Author Share Posted September 3, 2007 well i guess I'll leave it as it is, i was searching and a lot of people have the same issue, bt every one says the same that there is no need for the format when you can view it on a browser that gives you the right format. plus $dom->formatOutput = yes; only works if you create the file from scratch meaning you can't add nothing else to it. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted September 3, 2007 Share Posted September 3, 2007 oh so danielo if it was oyu you wouldn't pay mind to the format? Not really, as long as it's valid syntax, but if you can do what corillo181 says (I didn't bother to check), then you might as well do so. I just realized that I talked to you (corillo181) about you in third person... Quote Link to comment Share on other sites More sharing options...
d22552000 Posted September 3, 2007 Share Posted September 3, 2007 lol, I think Danial has had a long day. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.