How can i create xml file from userdata using a schema?

Hi

I have a situation where i need to create a xml document from the data given by the users.

In this part i’ve no problems. I tried both simplexml and DOMDocument for that.

And also i’ve a scheme for the xml document.

Now I need to create the xml document with respect to the schema.

For example, if the schema is

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified">
<xs:element name="formpatterns">
<xs:element name="pan" type="pantype"/>
<xs:element name="name" type="nametype"/>
<xs:element name="fatherName" type="nametype"/>
<xs:group ref="address"/>
<xs:element name="dob" type="xs:date"/>
</xs:schema>

and if user gives the data for pan, name, fathername, address, dob then
i need to create the xml document automatically by matching the schema and data.

Any help??

I found a class for you: XSLTProcessor
Use it in 3 steps:

  1. construct.
  2. Import a style sheet using XSLTProcessor::importStylesheet
  3. Transform to XML using XSLTProcessor::transformToXML

i think xml stylesheet is different from xml schema…

I dont know whether i’m right…

But xsl is a xml stylesheet which says how the xml data should be styled , while xsd is the xml schema which says the structure of the xml…

Any body any ideas on this?

The schema (xsd) is used for validation of XML documents, the style-sheet is used for transformations.

Yes, you are right.

I’ve a schema from a third party and i’ve create my own xml document from the user given data with respect to the schema.

That’s what i exactly want…

If there is no other way of doing it by predefined classes, then anybody please tell me the way to do it programatically.