0
votes

I have a XSD of the format:

<?xml version="1.0" encoding="utf-16"?>
<root>

    <xs:schema --->
      ..
      ..
      </xs:schema>

       <xs:schema -->
      ..
      ..
      </xs:schema -->

       <xs:schema -->
      ..
      ..
      </xs:schema -->


</root> 

It gives an error when compiled using XJC compiler at line 1 "Content is not allowed in prolog". If I change the encoding to , "ISO-8859-1"

it gives followwing error:

[ERROR] Unexpected <root> appears at line 2 column 10
  line 2 of ****.xsd Failed to parse a schema.

If I remove the "root" tag, from the XSD, it starts giving the following error:

  [ERROR] The markup in the document following the root element must be well-formed.
  line 44 of file:****.xsd

Failed to parse a schema.

My question is whether we can use XJC to compile a XSD with more than 1 schema tag. I had tried this with following file format :

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

<xs:element name="shiporder">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="abc" type="xs:string"/>
      <xs:element name="cdf">
      /xs:element>

    </xs:sequence>
    <xs:attribute name="orderid" type="xs:string" use="required"/>
  </xs:complexType>
</xs:element>

</xs:schema>

it worked perfectly well for the above , creating classes appropriately.

Does it has something to do with the namespace declaration?

1

1 Answers

0
votes

In principle, the XSD spec allows multiple xs:schema elements to be included in the same XML document, so what you are trying to do is not unreasonable. In practice, a lot of XSD software (perhaps most XSD software) is not prepared for schema documents in which the xs:schema element is not the outermost element in the XML document, and even when software does support other cases, different programs don't always agree on how to behave.

See this Stack Overflow question for further discussion, including a passionate argument from a misinformed party that there is no XSD software at all that supports input of the kind you describe.

With XJC, your best option appears to be to put each xs:schema element in a separate XML document and use (a) a single driver file to import or include each of them in turn, or (b) to put them all in the same directory and hand XJC the name of the directory; it will scan the directory for schema files and compile them. You may also be able to do something with the -wsdl option.