validate element with attribute xsi:type="xsd:string"

Discussion in 'XML' started by johnsocs@gmail.com, Jun 8, 2005.

  1. Guest

    How do you validate the following XML document, I'm having problems
    with element 'one' with the attribute xsi:type="xsd:string"

    <?xml version="1.0" encoding="UTF-8"?>
    <zero xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <one xsi:type="xsd:string">test</one>
    </zero>
     
    , Jun 8, 2005
    #1
    1. Advertising

  2. wrote:

    > How do you validate the following XML document, I'm having problems
    > with element 'one' with the attribute xsi:type="xsd:string"
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <zero xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    > <one xsi:type="xsd:string">test</one>
    > </zero>


    To validate you need a schema I think, I don't know any validators
    checking the xsi:type attribute alone.
    And of course you need to bind the prefix xsd e.g.
    <zero
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 8, 2005
    #2
    1. Advertising

  3. Guest

    I've been working with the following schema without luck.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >

    <xsd:element name="zero">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element ref="one" maxOccurs="1"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>

    <xsd:element name="one" type="xsd:string"/>

    <xsd:complexType name="xsd:string">
    <xsd:simpleContent>
    <xsd:extension base="xsd:string"/>
    </xsd:simpleContent>
    </xsd:complexType>
    </xsd:schema>
     
    , Jun 8, 2005
    #3
  4. wrote:

    > I've been working with the following schema without luck.
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
    >
    > <xsd:element name="zero">
    > <xsd:complexType>
    > <xsd:sequence>
    > <xsd:element ref="one" maxOccurs="1"/>
    > </xsd:sequence>
    > </xsd:complexType>
    > </xsd:element>
    >
    > <xsd:element name="one" type="xsd:string"/>
    >
    > <xsd:complexType name="xsd:string">
    > <xsd:simpleContent>
    > <xsd:extension base="xsd:string"/>
    > </xsd:simpleContent>
    > </xsd:complexType>


    Why are you trying to redefine xsd:string then?


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 8, 2005
    #4
  5. Guest

    I'm trying to write a schema to validate the xml document, and I dont
    know how to handle the one element. Based on the following I came up
    with the previous schema.

    <?xml version="1.0" encoding="UTF-8"?>
    <zero xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <one xsi:type="A">test</one>
    </fullName>

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >

    <xsd:element name="zero">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element ref="one" maxOccurs="1"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>

    <xsd:element name="one" type="A"/>

    <xsd:complexType name="A">
    <xsd:simpleContent>
    <xsd:extension base="xsd:string"/>
    </xsd:simpleContent>
    </xsd:complexType>

    </xsd:schema>
     
    , Jun 8, 2005
    #5
  6. wrote:

    > I'm trying to write a schema to validate the xml document, and I dont
    > know how to handle the one element.


    The schema is simple but you need to bind the prefix xsd as already
    explained:

    <?xml version="1.0" encoding="UTF-8"?>
    <zero xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="test2005060801Xsd.xml"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <one xsi:type="xsd:string">test</one>
    </zero>

    then the schema looks as

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    version="1.0">

    <xs:element name="zero">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="one" type="xs:string" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    </xs:schema>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 8, 2005
    #6
  7. Guest

    Thanks!
     
    , Jun 8, 2005
    #7
  8. Guest

    If you could help me out with more more thing that would be great, you
    have been very helpful.

    Again trying to build a schema based on the following XML. I
    understand how to describe the 'one' element I dont understand how to
    describe the soap message within the schema.

    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>

    <one xsi:type="xsd:string>test</one>

    </soapenv:Body>
    </soapenv:Envelope>


    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    version="1.0">

    <xsd:element name="zero">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="one" type="xsd:string"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>

    </xsd:schema>

    Thanks in advance.
     
    , Jun 8, 2005
    #8
  9. wrote:

    > If you could help me out with more more thing that would be great, you
    > have been very helpful.
    >
    > Again trying to build a schema based on the following XML. I
    > understand how to describe the 'one' element I dont understand how to
    > describe the soap message within the schema.
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <soapenv:Envelope
    > xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    > xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    > <soapenv:Body>
    >
    > <one xsi:type="xsd:string>test</one>
    >
    > </soapenv:Body>
    > </soapenv:Envelope>


    You need to have two schemas then as one schema can only describe the
    elements in one particular target namespace while your XML instance
    above has elements in the namespace
    http://schemas.xmlsoap.org/soap/envelope/ and in no namespace.

    So a possible solution is

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified"
    targetNamespace="http://schemas.xmlsoap.org/soap/envelope/"
    version="1.0">

    <xs:import schemaLocation="test2005060902Xsd.xml" />

    <xs:element name="Envelope">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="Body">
    <xs:complexType>
    <xs:sequence>
    <xs:element ref="one" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    </xs:schema>

    where the imported schema test2005060902Xsd.xml is

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    version="1.0">

    <xs:element name="one" type="xs:string" />

    </xs:schema>

    and the instance is

    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/
    test2005060901XSd.xml">
    <soapenv:Body>
    <one xsi:type="xsd:string">test</one>
    </soapenv:Body>
    </soapenv:Envelope>


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 9, 2005
    #9
    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. =?Utf-8?B?WUM=?=

    XSI type not supported withing web.config file

    =?Utf-8?B?WUM=?=, Apr 5, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    402
    =?Utf-8?B?WUM=?=
    Apr 5, 2006
  2. Naresh Agarwal
    Replies:
    1
    Views:
    780
    Christian Ludwig
    Jan 13, 2004
  3. Replies:
    0
    Views:
    1,425
  4. killy971
    Replies:
    2
    Views:
    688
    Johannes Koch
    Aug 15, 2008
  5. den
    Replies:
    0
    Views:
    282
Loading...

Share This Page