Click to See Complete Forum and Search --> : xml to xsd
jdoy
November 26th, 2003, 10:09 AM
Hi all,
I have a question for you and i hope you could help me...
Well, is it possible from an XML file to have an XSD file composed by the value i have entered in my XML file.
I mean, i've created cd_collection.xsd qhich desribe the structure of a cd collection. Then i have also cd_collection.xml which has values and is validated by the xsd file. But then i would like to have a cd_collection_bis.xsd which is a schema but with the values of my xml file.... How can i do that??
Thanks very much for helping
Jerome
khp
November 26th, 2003, 11:08 AM
I suppose you could use an xsl stylesheet to transform the xml file to the xsd file you want.
But I'am not sure I understand where you are going with this.
You got your data (the xml file) your structure description (the xsd file). And you need values from the xml file to create another xsd file for what ?.
jdoy
November 26th, 2003, 11:42 AM
Hi,
thanks for answering... Well I guess i can use an xsl stylesheet to transform my xml. But isnt'it only to transform in HTML?? You mean it'apossible to transform in XSD??
Well, i just want to have this new XSD schema to then make a link to an XSP page (well quite complicated...)
The fact is that i like to create an example like that:
XML: file
<function>
<name>example</name>
<type>int</type>
</function>
<function>
<name>example_bis</name>
<type>string</type>
</function>
.....
And i like to have a XSD file like that:
<xs:element name ="example">
<xs:attribute name ="int" use ="required"/>
</xs:element>
<xs:element name ="example_bis">
<xs:attribute name ="string" use= "required"/>
</xs:element>
You see what i mean now ?? But i really don't know how to proceed, so if you could help me, it would be very nice of you....
khp
November 26th, 2003, 06:46 PM
Originally posted by jdoy
thanks for answering... Well I guess i can use an xsl stylesheet to transform my xml. But isnt'it only to transform in HTML??
No no, you can use xsl to transform xml files to pretty much any text base format. But admittedly setting the namespace in the output can be somewhat tricky.
The following should work, on your example
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xs="http://www.w3c.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xs:schema xmlns:xs="http://www.w3c.org/2001/XMLSchema">
<xsl:apply-templates select="*"/>
</xs:schema>
</xsl:template>
<xsl:template match="function">
<xs:element>
<xsl:attribute name="name">
<xsl:value-of select="name"/>
</xsl:attribute>
<xs:attribute>
<xsl:attribute name="name">
<xsl:value-of select="type"/>
</xsl:attribute>
<xsl:attribute name="use">
<xsl:text>required</xsl:text>
</xsl:attribute>
</xs:attribute>
</xs:element>
</xsl:template>
</xsl:stylesheet>
jdoy
November 27th, 2003, 02:50 AM
Thanks very much for answering so greatly....
I'll try to do that, in fact i thought XSL was only for to transform xml to html, i didn't konw we couls use it for other text format...
Thanks a lot!!!!
Jerome
jdoy
November 28th, 2003, 03:25 AM
Well...
It works almost, but i always have to correct the namespaces, and there are also namesspaces which appear everywhere... Do you know how to proceed to correct this problem???
Thanks a lot...
khp
November 28th, 2003, 01:57 PM
Sorry I don't quite understand what you are saying. Showing me your output would be so much more usefull.
Anyways it's very very difficult for me to tell you anything, without any information about your system. If I am to help you with a problem, I have to be able to reproduce it.
Edit: Ahh I see you moved to another thread :)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.