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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • johnsocs@gmail.com

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

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

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

  • Martin Honnen

    #2
    Re: validate element with attribute xsi:type=&quot; xsd:string&quot ;



    johnsocs@gmail. com wrote:
    [color=blue]
    > How do you validate the following XML document, I'm having problems
    > with element 'one' with the attribute xsi:type="xsd:s tring"
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <zero xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
    > <one xsi:type="xsd:s tring">test</one>
    > </zero>[/color]

    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

    Comment

    • johnsocs@gmail.com

      #3
      Re: validate element with attribute xsi:type=&quot; xsd:string&quot ;

      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:complexTyp e>
      <xsd:sequence >
      <xsd:element ref="one" maxOccurs="1"/>
      </xsd:sequence>
      </xsd:complexType >
      </xsd:element>

      <xsd:element name="one" type="xsd:strin g"/>

      <xsd:complexTyp e name="xsd:strin g">
      <xsd:simpleCont ent>
      <xsd:extensio n base="xsd:strin g"/>
      </xsd:simpleConte nt>
      </xsd:complexType >
      </xsd:schema>

      Comment

      • Martin Honnen

        #4
        Re: validate element with attribute xsi:type=&quot; xsd:string&quot ;



        johnsocs@gmail. com wrote:
        [color=blue]
        > 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:complexTyp e>
        > <xsd:sequence >
        > <xsd:element ref="one" maxOccurs="1"/>
        > </xsd:sequence>
        > </xsd:complexType >
        > </xsd:element>
        >
        > <xsd:element name="one" type="xsd:strin g"/>
        >
        > <xsd:complexTyp e name="xsd:strin g">
        > <xsd:simpleCont ent>
        > <xsd:extensio n base="xsd:strin g"/>
        > </xsd:simpleConte nt>
        > </xsd:complexType >[/color]

        Why are you trying to redefine xsd:string then?


        --

        Martin Honnen

        Comment

        • johnsocs@gmail.com

          #5
          Re: validate element with attribute xsi:type=&quot; xsd:string&quot ;

          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">te st</one>
          </fullName>

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

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

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

          <xsd:complexTyp e name="A">
          <xsd:simpleCont ent>
          <xsd:extensio n base="xsd:strin g"/>
          </xsd:simpleConte nt>
          </xsd:complexType >

          </xsd:schema>

          Comment

          • Martin Honnen

            #6
            Re: validate element with attribute xsi:type=&quot; xsd:string&quot ;



            johnsocs@gmail. com wrote:
            [color=blue]
            > I'm trying to write a schema to validate the xml document, and I dont
            > know how to handle the one element.[/color]

            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:noNamespace SchemaLocation= "test2005060801 Xsd.xml"
            xmlns:xsd="http ://www.w3.org/2001/XMLSchema">
            <one xsi:type="xsd:s tring">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

            Comment

            • johnsocs@gmail.com

              #7
              Re: validate element with attribute xsi:type=&quot; xsd:string&quot ;

              Thanks!

              Comment

              • johnsocs@gmail.com

                #8
                Re: validate element with attribute xsi:type=&quot; xsd:string&quot ;

                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:Envelo pe
                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:s tring>test</one>

                </soapenv:Body>
                </soapenv:Envelop e>


                <?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:complexTyp e>
                <xsd:sequence >
                <xsd:element name="one" type="xsd:strin g"/>
                </xsd:sequence>
                </xsd:complexType >
                </xsd:element>

                </xsd:schema>

                Thanks in advance.

                Comment

                • Martin Honnen

                  #9
                  Re: validate element with attribute xsi:type=&quot; xsd:string&quot ;



                  johnsocs@gmail. com wrote:
                  [color=blue]
                  > 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:Envelo pe
                  > 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:s tring>test</one>
                  >
                  > </soapenv:Body>
                  > </soapenv:Envelop e>[/color]

                  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"
                  elementFormDefa ult="qualified"
                  targetNamespace ="http://schemas.xmlsoap .org/soap/envelope/"
                  version="1.0">

                  <xs:import schemaLocation= "test2005060902 Xsd.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 test2005060902X sd.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:Envelo pe
                  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:schemaLocat ion="http://schemas.xmlsoap .org/soap/envelope/
                  test2005060901X Sd.xml">
                  <soapenv:Body >
                  <one xsi:type="xsd:s tring">test</one>
                  </soapenv:Body>
                  </soapenv:Envelop e>


                  --

                  Martin Honnen

                  Comment

                  Working...