mavera2 Posted September 8, 2011 Share Posted September 8, 2011 With the following code i can create an xml file. <?php $myXML = new SimpleXMLElement("<myroot></myroot>"); $title= $myXML->addChild('title'); $title->addAttribute('number','12'); $titleName= $title->addChild('titleName', 'title1'); $titleLink= $title->addChild('titleLink', 'link1'); Header('Content-type: text/xml'); echo $myXML->asXML(); ?> But when i check the validity of xml file http://www.validome.org/xml/validate/ This error occurs: Can not find declaration of element 'myroot'. I suppose that the problem is missing of !DOCTYPE and !ELEMENT lines. How can i create valid XML documents with PHP automatically?? Is it possible to make it without writing doctype and element types for the whole element types of xml by hand $title, $titleName and $titleLink Thank you Quote Link to comment https://forums.phpfreaks.com/topic/246744-valid-xml-creation-with-php/ Share on other sites More sharing options...
Cagecrawler Posted September 8, 2011 Share Posted September 8, 2011 It's the validator that's the problem, your code produces a valid output. <?xml version="1.0"?> <myroot><title number="12"><titleName>title1</titleName><titleLink>link1</titleLink></title></myroot> Try http://validator.w3.org/. Quote Link to comment https://forums.phpfreaks.com/topic/246744-valid-xml-creation-with-php/#findComment-1267143 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.