converting xml file to schema file problem

Discussion in 'XML' started by sharan, Oct 7, 2009.

  1. sharan

    sharan Guest

    i am converting a xml file having namespaces in to schema file (.xsd)
    for validation.

    my xml file is
    test.xml
    -----------------------------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <root xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:h="http://www.w3.org/TR/html4/"
    xmlns:f="http://www.w3.org/TR/scxml/">
    <h:table>
    <h:tr>vegitables</h:tr>
    <h:td>Apples</h:td>
    </h:table>

    <f:table>
    <f:name>African Coffee Table</f:name>
    <f:data>hari</f:data>
    <f:length>oum</f:length>
    </f:table>
    </root>
    ----------------------------------------------------------

    I converted this xml file in to schema file.
    test.xsd
    ----------------------------------------------------------
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:h="http://www.w3.org/TR/html4/"
    xmlns:j="http://www.w3.org/TR/scxml/">
    <xs:element name="root">
    <xs:complexType>
    <xs:sequence>

    <xs:element name="h:table">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="h:tr" type="xs:string"/>
    <xs:element name="h:td" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    <xs:element name="f:table">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="f:name" type="xs:string"/>
    <xs:element name="f:data" type="xs:string"/>
    <xs:element name="f:length" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    </xs:sequence>
    </xs:complexType>
    </xs:element>

    </xs:schema>
    ------------------------------------------------------------------
    when i am validating this schema file
    it is showing eroors in OUTPUT
    -------------------------------------------------------------------
    temp1.xsd:9: element element: Schemas parser error : Element '{http://
    www.w3.org/2001/XMLSchema}element', attribute 'name': 'h:table' is not
    a valid value of the atomic type 'xs:NCName'.

    temp1.xsd:18: element element: Schemas parser error : Element '{http://
    www.w3.org/2001/XMLSchema}element', attribute 'name': 'f:table' is not
    a valid value of the atomic type 'xs:NCName'.

    temp.xml:4: element root: Schemas validity error : Element 'root': No
    matching global declaration available for the validation root.
    temp.xml fails to validate
    -------------------------------------------------------------------

    I want to know that while converting above xml file to schema file, is
    there
    any problem or errer in converted schema file.
    And i also want to know, that, why these error are coming and how to
    overcome
    these.

    note: for validation we can use testSchema.c. which is in libxml2 api.

    Thanks in advance
    sharan, Oct 7, 2009
    #1
    1. Advertising

  2. sharan

    harry Guest

    On Oct 7, 2:41 pm, sharan <> wrote:
    > i am converting a xml file having namespaces in to schema file (.xsd)
    > for validation.
    >
    > my xml file is
    > test.xml
    > -----------------------------------------------------------
    > <?xml version="1.0" encoding="UTF-8"?>
    > <root xmlns:xs="http://www.w3.org/2001/XMLSchema"
    > xmlns:h="http://www.w3.org/TR/html4/"
    > xmlns:f="http://www.w3.org/TR/scxml/">
    > <h:table>
    > <h:tr>vegitables</h:tr>
    > <h:td>Apples</h:td>
    > </h:table>
    >
    > <f:table>
    > <f:name>African Coffee Table</f:name>
    > <f:data>hari</f:data>
    > <f:length>oum</f:length>
    > </f:table>
    > </root>
    > ----------------------------------------------------------
    >
    > I converted this xml file in to schema file.
    > test.xsd
    > ----------------------------------------------------------
    > <?xml version="1.0" encoding="ISO-8859-1"?>
    > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    > xmlns:h="http://www.w3.org/TR/html4/"
    > xmlns:j="http://www.w3.org/TR/scxml/">
    > <xs:element name="root">
    > <xs:complexType>
    > <xs:sequence>
    >
    > <xs:element name="h:table">
    > <xs:complexType>
    > <xs:sequence>
    > <xs:element name="h:tr" type="xs:string"/>
    > <xs:element name="h:td" type="xs:string"/>
    > </xs:sequence>
    > </xs:complexType>
    > </xs:element>
    >
    > <xs:element name="f:table">
    > <xs:complexType>
    > <xs:sequence>
    > <xs:element name="f:name" type="xs:string"/>
    > <xs:element name="f:data" type="xs:string"/>
    > <xs:element name="f:length" type="xs:string"/>
    > </xs:sequence>
    > </xs:complexType>
    > </xs:element>
    >
    > </xs:sequence>
    > </xs:complexType>
    > </xs:element>
    >
    > </xs:schema>
    > ------------------------------------------------------------------
    > when i am validating this schema file
    > it is showing eroors in OUTPUT
    > -------------------------------------------------------------------
    > temp1.xsd:9: element element: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}element', attribute 'name': 'h:table' is not
    > a valid value of the atomic type 'xs:NCName'.
    >
    > temp1.xsd:18: element element: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}element', attribute 'name': 'f:table' is not
    > a valid value of the atomic type 'xs:NCName'.
    >
    > temp.xml:4: element root: Schemas validity error : Element 'root': No
    > matching global declaration available for the validation root.
    > temp.xml fails to validate
    > -------------------------------------------------------------------
    >
    > I want to know that while converting above xml file to schema file, is
    > there
    > any problem or errer in converted schema file.
    > And i also want to know, that, why these error are coming and how to
    > overcome
    > these.
    >
    > note: for validation we can use testSchema.c. which is in libxml2 api.
    >
    > Thanks in advance


    Sorry by mistake it is showing different encoding in both file.
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml version="1.0" encoding="ISO-8859-1"?>

    But i am using same encoding in both file, like:
    <?xml version="1.0" encoding="UTF-8"?>
    harry, Oct 7, 2009
    #2
    1. Advertising

  3. sharan wrote:
    > i am converting a xml file having namespaces in to schema file (.xsd)
    > for validation.
    >
    > my xml file is
    > test.xml
    > -----------------------------------------------------------
    > <?xml version="1.0" encoding="UTF-8"?>
    > <root xmlns:xs="http://www.w3.org/2001/XMLSchema"
    > xmlns:h="http://www.w3.org/TR/html4/"
    > xmlns:f="http://www.w3.org/TR/scxml/">
    > <h:table>
    > <h:tr>vegitables</h:tr>
    > <h:td>Apples</h:td>
    > </h:table>
    >
    > <f:table>
    > <f:name>African Coffee Table</f:name>
    > <f:data>hari</f:data>
    > <f:length>oum</f:length>
    > </f:table>
    > </root>


    You will need three schemas, one for each namespace used (i.e. no
    namespace for the root element and two different namespaces for the
    other elements). Then the schema for the root element needs to import
    the other two schemas and reference the type or element definitions in
    those schemas.


    --

    Martin Honnen
    http://msmvps.com/blogs/martin_honnen/
    Martin Honnen, Oct 7, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,497
    Markus
    Nov 23, 2005
  2. Bart Torbert
    Replies:
    1
    Views:
    554
    Ron Reidy
    Jul 2, 2004
  3. Marcello Villani

    converting from RDF schema to XML schema

    Marcello Villani, Nov 25, 2004, in forum: XML
    Replies:
    1
    Views:
    446
    Andy Dingley
    Nov 26, 2004
  4. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,172
    Stanimir Stamenkov
    Apr 25, 2005
  5. Replies:
    3
    Views:
    2,797
Loading...

Share This Page