When i define XML schema in the mec.xsd it doesn't work for the element. How can i resolve this? Thanks.
<l:primary>XML</l:primary>
mec.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<people xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.com mc.xsd"
xmlns:l="http://www.example2.com"
xmlns="http://www.example.com">
<person>
<name>Marcus</name>
<language>
<l:primary>XML</l:primary>
</language>
</person>
</people>
mc.xsd
<xs:schema version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com"
xmlns="http://www.example.com"
elementFormDefault="qualified">
<xs:element name="people">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="person">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="language">
<xs:complexType mixed="true">
<xs:element name="primary" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
When you use multiple namespaces in an XML document, you can define one namespace as the default namespace to create a cleaner looking document. The default namespace is declared in the root element and applies to all unqualified elements in the document. Default namespaces apply to elements only, not to attributes.
In writing XSD schemas, you can use the XSD targetNamespace attribute to specify a target namespace. This topic describes how the XSD targetNamespace, elementFormDefault, and attributeFormDefault attributes work, how they affect the XML instance that is generated, and how XPath queries are specified with namespaces.
While a properly formed XML file can only have a single root element, an XSD or DTD file can contain multiple roots.
Schemas can be composed of one or more XML documents. These schema documents can be explicitly joined together using the include and import elements.
you have to use xsd:import
to bring in an XSD from a different
namespace.
You have to Validate the xml document using only the main schema (mc.xsd).
primary.xsd (imported schema)
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
targetNamespace="http://www.example2.com">
<xs:element name="primary" type="xs:string"/>
</xs:schema>
mc.xsd (main schema)
<xs:schema version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com"
xmlns="http://www.example2.com"
elementFormDefault="qualified">
<xs:import namespace="http://www.example2.com" schemaLocation="primary.xsd"/>
<xs:element name="people">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="person">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="language">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element ref="primary"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With