3 Replies Latest reply: Dec 29, 2012 8:24 AM by tsuji RSS

    Creating XSD from XML

    NickTeh
      I'm new to XML/XSD. I want to create URL Service Data Control and I encounter an error. Any pointers on what is the actual error?

      Error
      The XML validation failed with the following error "Invalid text '<NewDataSet>
      <Table>
      <Country>Singapore</Country>
      <City>Singapore / Paya Lebar</City>
      </Table>
      <Table>
      <Country>Singapore</Country>
      <City>Singapore / Changi Airport</City>
      </Table>
      </NewDataSet>
      </string>' in element: 'string'", at line number 11.

      -----

      XML
      <?xml version="1.0" encoding="utf-8" ?>
      <string xmlns="http://www.webserviceX.NET">
      <NewDataSet>
      <Table>
      <Country>Singapore</Country>
      <City>Singapore / Paya Lebar</City>
      </Table>
      <Table>
      <Country>Singapore</Country>
      <City>Singapore / Changi Airport</City>
      </Table>
      </NewDataSet>
      </string>

      -----

      XSD
      <?xml version="1.0" encoding="utf-8"?>
      <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.webserviceX.NET" elementFormDefault="qualified">
           <element name="string">
           <complexType>
           <sequence>
                <element name="NewDataSet" minOccurs="0" maxOccurs="unbounded">
                <complexType>
                <sequence>
                     <element name="Table" minOccurs="0" maxOccurs="unbounded">
                     <complexType>
                     <sequence>
                          <element name="Country" type="string" minOccurs="0"/>
                          <element name="City" type="string" minOccurs="0"/>
                     </sequence>
                     </complexType>
                     </element>
                </sequence>
                </complexType>
                </element>
           </sequence>
           </complexType>
           </element>
      </schema>

      Edited by: NickTeh on 24-Dec-2012 08:30
        • 1. Re: Creating XSD from XML
          Jason_(A_Non)
          In your XML, this line
          <string xmlns="http://www.webserviceX.NET" targetNamespace="http://www.webserviceX.NET">
          should just be
          <string xmlns="http://www.webserviceX.NET">
          That gets it past validation in XMLSpy at least.
          • 2. Re: Creating XSD from XML
            NickTeh
            Sorry XML got error and I corrected it already. I can't change the XML. I can only create XSD to extract data from the XML. Now my problem lies with validating the XSD when I creating URL Service Data Control in JDeveloper.
            • 3. Re: Creating XSD from XML
              tsuji
              NickTeh wrote:
              Error
              The XML validation failed with the following error "Invalid text '<NewDataSet>
              <Table>
              <Country>Singapore</Country>
              <City>Singapore / Paya Lebar</City>
              </Table>
              <Table>
              <Country>Singapore</Country>
              <City>Singapore / Changi Airport</City>
              </Table>
              </NewDataSet>
              </string>' in element: 'string'", at line number 11.
              On the face of it: being alluding to 'Invalid text'... suggests the validator did not anticipate text content for string tag. The only reasonable deduction is that the whole <NewDataSet>...</NewDataSet> is actually embedded in a CDATA section (or simple an escaped form of it) representing its payload, namely, what it really receves is this:
              <string><![CDATA[
              <NewDataSet>
              <Table>
              <Country>Singapore</Country>
              <City>Singapore / Paya Lebar</City>
              </Table>
              <Table>
              <Country>Singapore</Country>
              <City>Singapore / Changi Airport</City>
              </Table>
              </NewDataSet>
              ]]></string>
              So your task is to get the text content of string element and then parse the text content to an xml document proper and then validating it using the proper subset with NewDataSet as root...