E
Eric Lilja
Hello, this is an xml-file with a nested DTD. It validates, test-1-
with-dtd.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE persons [
<!ELEMENT persons (person*)>
<!ELEMENT person EMPTY>
<!ATTLIST person name CDATA #REQUIRED>
]>
<persons>
<person name="Eric Lilja" />
</persons>
Now I want to use an XML Schema (located in a separate file) instead
of a nested DTD. I've created the following schema (test-1.xsd):
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="myns"
xmlns="myns"
elementFormDefault="unqualified">
<xs:element name="persons">
<xs:complexType>
<xs:sequence>
<xs:element name="person">
<xs:complexType>
<xs:attribute name="name" type="xs:string"
use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I want this schema to accomplish what my DTD above accomplishes. The
schema itself validates, but this xml file that tries to use does not.
test-1-with-xsd.xml:
<?xml version="1.0" encoding="utf-8"?>
<persons xmlns="myns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xsi:schemaLocation="myns test-1.xsd">
<person name="Eric Lilja"/>
</persons>
The validator says:
Location: 4:4
Description: cvc-complex-type.2.4.a: Invalid content was found
starting with element 'person'. One of '{person}' is expected.
I'm very new with xml (second day, hehe) and this is my very first
schema. What is the problem? I guess it's a problem with the XML
schema even though it validates becuase the test-1-with-xsd.xml that
uses it looks OK to me (and it should look like the one using the
DTD).
- Eric
with-dtd.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE persons [
<!ELEMENT persons (person*)>
<!ELEMENT person EMPTY>
<!ATTLIST person name CDATA #REQUIRED>
]>
<persons>
<person name="Eric Lilja" />
</persons>
Now I want to use an XML Schema (located in a separate file) instead
of a nested DTD. I've created the following schema (test-1.xsd):
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="myns"
xmlns="myns"
elementFormDefault="unqualified">
<xs:element name="persons">
<xs:complexType>
<xs:sequence>
<xs:element name="person">
<xs:complexType>
<xs:attribute name="name" type="xs:string"
use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I want this schema to accomplish what my DTD above accomplishes. The
schema itself validates, but this xml file that tries to use does not.
test-1-with-xsd.xml:
<?xml version="1.0" encoding="utf-8"?>
<persons xmlns="myns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xsi:schemaLocation="myns test-1.xsd">
<person name="Eric Lilja"/>
</persons>
The validator says:
Location: 4:4
Description: cvc-complex-type.2.4.a: Invalid content was found
starting with element 'person'. One of '{person}' is expected.
I'm very new with xml (second day, hehe) and this is my very first
schema. What is the problem? I guess it's a problem with the XML
schema even though it validates becuase the test-1-with-xsd.xml that
uses it looks OK to me (and it should look like the one using the
DTD).
- Eric