Jump to content

Valid XML creation with PHP


mavera2

Recommended Posts

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.