2

I have an XSD file which has 4 xsd:schema elements in it, which are related and use each other. I've tried to bind that schema into a dataset with ReadXmlSchema method but I've got this error:

There are multiple root elements

The reason is there are 4 xsd:schema in one file. I cannot combine or split them.

Do you have any suggestion?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
blackmamba
  • 93
  • 1
  • 8

1 Answers1

2

The reason is there are 4 xsd:schema in one file. I can not combine or split them.

You can and you must split them. An XSD must be a well-formed XML document itself, and well-formed XML documents can only have a single root element.

Create a main XSD that uses xs:include or xs:import to bring in the other XSDs. Read more about the differences here. Examples follow...

Example using XSD include

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:include schemaLocation="1.xsd"/>
  <xs:include schemaLocation="2.xsd"/>
  <!-- ... -->
</xs:schema>

Example using XSD import

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://www.example.com/main"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:import namespace="http://www.example.com/1" schemaLocation="1.xsd"/>
  <xs:import namespace="http://www.example.com/2" schemaLocation="2.xsd"/>
  <!-- ... -->    
</xs:schema>
Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240