A little new to learning XSD.
If I have this XSD valid schema looking like this below:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>
How come this XML is not being validated correctly.
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
</note>
<optional>hi</optional>
If I try to validate the XML against the XSD it gives me the following error message.
The markup in the document following the root element must be well-formed.
Im using following validator engine:
https://www.liquid-technologies.com/online-xsd-validator
Where should I be able to make use of the optional element in my XML?
Thanks for all help
All XML documents, regardless of any associated schema, must have only 1 root element. You can't have this:
Your XML document has to look like this:
Or just:
XSD's can have multiple global elements defined, but that doesn't imply multiple root elements in a corresponding XML document.
In this case, I assumed you've posted only an excerpt of the XSD, but maybe there's another element that's meant to be the root element and is itself a parent of both
noteandoptional, so really your XML is meant to be something like:In any case, you need to decide which element is meant to be the root. It's an annoying thing about XSDs is that there's no way to mark one global element out of many, as the root. For that reason many XSDs are designed with just one global element and the rest are either global complex/simple types with child elements underneath the one global element.
If this XSD is one of your own making, then I suggest having just one global element.