raymak Posted June 2, 2014 Share Posted June 2, 2014 Hello, I am trying to generate XML file and print the xml value in the browser. I am having had time create child element and adding attribute inside the child element. Structure I am trying to create is: <applications> <app appname="Notepad++" /> </applications> Here is the code I'm trying to accomplish the above format: $doc = new DOMDocument("1.0"); $doc->formatOutput = true; $main = $doc->createElement("Applications"); $doc->appendChild( $main); $child = $doc->createElement( "app" ); $attr = $doc->appendChild($child); $attr->setAttribute("AppName", "NotePad++"); echo $doc->saveXML(); I am not sure what I'm doing wrong, but I get below error when I browse the php page: The XML page cannot be displayed Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. Only one top level element is allowed in an XML document. Error processing resource 'http://localhost/servers/xmldoc.php'. ... <app AppName="NotePad++"/>-^ Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.