corillo181 Posted August 26, 2007 Share Posted August 26, 2007 i have this code to insert context into xml the problem is when the context is inserted a extra blank line is inserted.. and if you know about xml you can't have no extra blank line.. this is the code $dom = new DomDocument(); $dom->load('xml.xml'); $books= $dom->appendChild($dom->createElement('artists')); $book= $books->appendChild($dom->createElement('artist')); $tittle= $book->appendChild($dom->createElement('tittle')); $tittle->appendChild($dom->createTextNode('the malo')); $dom->ignoreWhite = true; $dom->formatOutput = true; $dom->save('xml.xml'); and this is the result 1 <?xml version="1.0"?> 2 <artists> 3 <artist> 4 <tittle>the malo</tittle> 5 </artist> 6 </artists> 7 Quote Link to comment https://forums.phpfreaks.com/topic/66716-solved-extra-line-in-xml/ Share on other sites More sharing options...
matthewhaworth Posted August 26, 2007 Share Posted August 26, 2007 i have this code to insert context into xml the problem is when the context is inserted a extra blank line is inserted.. and if you know about xml you can't have no extra blank line.. this is the code $dom = new DomDocument(); $dom->load('xml.xml'); $books= $dom->appendChild($dom->createElement('artists')); $book= $books->appendChild($dom->createElement('artist')); $tittle= $book->appendChild($dom->createElement('tittle')); $tittle->appendChild($dom->createTextNode('the malo')); $dom->ignoreWhite = true; $dom->formatOutput = true; $dom->save('xml.xml'); and this is the result 1 <?xml version="1.0"?> 2 <artists> 3 <artist> 4 <tittle>the malo</tittle> 5 </artist> 6 </artists> 7 I'm not the best with xml, but does that matter? Perhaps PHP just goes onto the next line ready to input data http://uk.php.net/manual/en/ref.dom.php Quote Link to comment https://forums.phpfreaks.com/topic/66716-solved-extra-line-in-xml/#findComment-334277 Share on other sites More sharing options...
corillo181 Posted August 26, 2007 Author Share Posted August 26, 2007 the problem with living a blank line is that next time you try to read the code is going throw a error which is Warning: DOMDocument::load() [function.DOMDocument-load]: Extra content at the end of the document in file:///C%3A/wamp/www/xml.xml, line: 7 in C:\wamp\www\Untitled-2.php on line 5 Quote Link to comment https://forums.phpfreaks.com/topic/66716-solved-extra-line-in-xml/#findComment-334298 Share on other sites More sharing options...
corillo181 Posted August 26, 2007 Author Share Posted August 26, 2007 man where are the php guru to help me out with this.!!!!!!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/66716-solved-extra-line-in-xml/#findComment-334333 Share on other sites More sharing options...
matthewhaworth Posted August 26, 2007 Share Posted August 26, 2007 Perhaps the line was in there to begin with, before php dealt with it? Delete absolutely everything out of the xml file and try again? Quote Link to comment https://forums.phpfreaks.com/topic/66716-solved-extra-line-in-xml/#findComment-334338 Share on other sites More sharing options...
corillo181 Posted August 26, 2007 Author Share Posted August 26, 2007 i already made it work with this code.. and the line kept putting it self in.. now I'm trying to work on giving each artist node a id value attribute while i do my search if any one knows how to do feel free to help. Quote Link to comment https://forums.phpfreaks.com/topic/66716-solved-extra-line-in-xml/#findComment-334364 Share on other sites More sharing options...
corillo181 Posted August 26, 2007 Author Share Posted August 26, 2007 does any one at least knows how to read xml ? i used xpath to make a query now i want to get only the name or what ever else i want, but it only gives me all the values with the riquired id. $dom = new DomDocument; $dom->load('test2.xml'); $xp = new domxpath($dom); $query = "/artists/artist[@id=1]"; $artist = $xp->query($query); foreach($artist as $name){ $xml = new SimpleXMLElement($name); print $xml->getElementsByTagName('name'); } Quote Link to comment https://forums.phpfreaks.com/topic/66716-solved-extra-line-in-xml/#findComment-334376 Share on other sites More sharing options...
Barand Posted August 26, 2007 Share Posted August 26, 2007 I didn't already have "xml.xml" to load so I commented out the second line. Running gave --> [pre] 1 <?xml version="1.0"?> 2 <artists> 3 <artist> 4 <tittle>the malo</tittle> 5 </artist> 6 </artists> Quote Link to comment https://forums.phpfreaks.com/topic/66716-solved-extra-line-in-xml/#findComment-334390 Share on other sites More sharing options...
corillo181 Posted August 26, 2007 Author Share Posted August 26, 2007 it's alright i already got everything working.. found some great tutorial at IBM dot com they really know their stuff Quote Link to comment https://forums.phpfreaks.com/topic/66716-solved-extra-line-in-xml/#findComment-334402 Share on other sites More sharing options...
Barand Posted August 26, 2007 Share Posted August 26, 2007 I assume you mean this one http://www.ibm.com/developerworks/opensource/library/os-xmldomphp/ Just to round off the topic <?php /** * data */ $tArray = array(1=>'The Tempest', 'Romeo and Juliet', 'Loves Labours Lost', 'King Henry V'); /** * create the xml file */ $dom = new DomDocument(); $dom->formatOutput = true; $books= $dom->appendChild($dom->createElement('artists')); foreach ($tArray as $id=>$t) { $book= $books->appendChild($dom->createElement('artist')); $book->setAttribute('id', $id); $tittle= $book->appendChild($dom->createElement('tittle')); $tittle->appendChild($dom->createTextNode($t)); } $dom->save('xml.xml'); /** * read it */ $xml = simplexml_load_file('xml.xml'); foreach ($xml->artist as $a) { echo "{$a['id']} : $a->tittle<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/66716-solved-extra-line-in-xml/#findComment-334407 Share on other sites More sharing options...
corillo181 Posted August 26, 2007 Author Share Posted August 26, 2007 nice way to end it i was just wokring on something like that you saved me the time Quote Link to comment https://forums.phpfreaks.com/topic/66716-solved-extra-line-in-xml/#findComment-334424 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.