|
|||||||
| XML Discussion and technical support for using and deploying XML applications and websites. |
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
different roots in XML document
Please, help me to understand what structure can have XML document which is described by this schema.
schema: <schema xmlns="http://www.w3.org/2001/XMLSchema"> <element name="A" /> <element name="B" /> </schema> Is it true that described XML document can have 2 possible roots? 1) <A /> 2) <B /> Or in other words: if schema doesn't have elements which have references to element "X" then this element "X" can be one of the roots of XML document. Is it true? |
|
#2
|
|||
|
|||
|
Technically, yes, an instance document can possibly have two root nodes using that schema. However, only one can be used at a time since a single document can only have a single root node.
|
|
#3
|
|||
|
|||
|
Thank you for reply. It is resolved.
Last edited by neuropunk; 03-19-2009 at 03:23 PM. |
|
#4
|
|||
|
|||
|
Want to make it in some way more difficult.
schema A.xsd Code:
<schema xmlns="http://www.w3.org/2001/XMLSchema"> <import schemaLocation="В.xsd"/> <element name="A" /> </schema> Code:
<schema xmlns="http://www.w3.org/2001/XMLSchema"> <element name="B" /> </schema> |
|
#5
|
|||
|
|||
|
Actually, the first schema isn't usable without the namespace attribute. The import element requires a namespace at minimum with the schemaLocation being optional. If one schema uses the same namespace as another, the include element is a better choice, which requires the schemaLocation at minimum.
The difference between import and include is the fact that the import element requires a namespace. import is used to include schemas or schema modules from other namespaces. include is used to include schemas or schema modules from the same namespace. |
|
#6
|
|||
|
|||
|
Thank you for corrections
schema A.xsd Code:
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://targetNamespace.com"> <import schemaLocation="В.xsd"/> <element name="A" /> </schema> Code:
<schema xmlns="http://www.w3.org/2001/XMLSchema"> <element name="B" /> </schema> Last edited by neuropunk; 03-20-2009 at 07:13 AM. |
|
#7
|
|||
|
|||
|
I found out. Answer to previous question is yes: if there is no elements which have references to element "X", then this element can be one of the roots of described XML document, and it isn't important that this element "X" was originaly defined in root schema or in one of imported/included schemas.
also I want to make small correction to previous post of rpgfan3233 regarding import and include instructions. you can look here for more details so it's resolved again |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|