I have an XML whose validation fails due to the following issue: The Prefix "example" For Element "example:lotNumber" Is Not Bound., Line '4', Column '19'. The Prefix "example" For Element "example:lotNumber" Is Not Bound.
I have declared the namespaces in the XSD since it is a default namespace it need not be included in XML again. How to make the XML pass the validation against the XSD?
do not wish to include the namespaces in XML <note xmlns:example="urn:example:mda:"> as it is a default namespace. I want to ensure the XML passes the validation even if I do not include the default namespaces in XML.
Following is my XML: Following is my XML and XSD:
<note >
<to>Tove</to>
<from>Jani</from>
<example:lotNumber>XML DEFAULT</example:lotNumber>
</note>
Following is the XSD containing default namespace:
Folloiwng is XSD:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:example="urn:example:mda:">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="to"/>
<xs:element type="xs:string" name="from"/>
<xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Also this just an example but the example can include any element such as:
example:helloXML DEFAULT NEW NEW ONE</example:hello>
example:hello1XML DEFAULT NEW NEW ONE</example:hello1>
Hence I cannot include the lotNumber in the XSD and make it pass the values are user-defined so it can be anything. How to make the XML pass the XSD validation when not included default namespace.
If I include the namespace in XML then it would work fine but user can skip then also it should pass:
<note xmlns:example="urn:example:mda:">
<to>Tove</to>
<from>Jani</from>
<example:lotNumber>XML DEFAULT NEW NEW ONE</example:lotNumber>
</note>
This is nothing to do with the schema. Before being even considered suitable for validation using the schema, your XML has to be well-formed, and if it contains an undeclared namespace prefix then it is ill-formed.