XML Schema Wont Work in Codeplot

C

Chase Preuninger

Here is my schema...

<?xml version="1.0"?>
<schema>
<element name="name">
<complexType>
<sequence>
<element name="first" type="string"/>
<element name="middle" type="string"/>
<element name="last" type="string"/>
</sequence>
</complexType>
</element>
</schema>


Here is my XML document...
<?xml version="1.0"?>
<name xsi:schemaLocation="TestSchema.xml">
<first>Chase</first>
<middle>T</middle>
<last>Preuninger</last>
</name>

Here is the parser output...

[Error] Document is invalid: no grammar found. Line 2, Column 6
[Error] Document root element "name", must match DOCTYPE root "null".
Line 2, Column 6
 
M

Martin Honnen

Chase said:
Here is my schema...

<?xml version="1.0"?>
<schema>

If you want to use the W3C XML schema language then you need to declare
a namespace e.g.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
and make sure the other elements are in that namespace too, as the type
like xs:string have to be.
<element name="name">
<complexType>
<sequence>
<element name="first" type="string"/>
<element name="middle" type="string"/>
<element name="last" type="string"/>
</sequence>
</complexType>
</element>
</schema>


Here is my XML document...
<?xml version="1.0"?>
<name xsi:schemaLocation="TestSchema.xml">

Your schema does not have a targetNamespace therefore you do not need
xsi:schemaLocation but rather xsi:noNamespaceSchemaLocation e.g.
<name
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="TestSchema.xml">
 
B

Bjoern Hoehrmann

* Chase Preuninger wrote in comp.text.xml:
Is there any way I could avoid using name spaces all tougher?

No, if you don't put the XML Schema attributes and elements into the
right namespace, applications cannot recognize them as XML Schema.
 
P

Peter Flynn

Chase said:
Is there any way I could avoid using name spaces all tougher?

Use a DTD instead.

<?xml version="1.0"?>
<!DOCTYPE name [
<!ELEMENT name (first,middle?,last)>
<!ELEMENT first (#PCDATA)>
<!ELEMENT middle (#PCDATA)>
<!ELEMENT last (#PCDATA)>
]>
<name>
<first>Chase</first>
<middle>T</middle>
<last>Preuninger</last>
</name>

But if you want complex validation, you need to use a Schema.

///Peter
 
M

Martin Honnen

Chase said:
Is there any way I could avoid using name spaces all tougher?

You can use the W3C XML schema language to define elements and
attributes in no namespace, simply by not having a targetNamespace as
you did. But for the schema elements itself you need to apply the
namespace http://www.w3.org/2001/XMLSchema, otherwise your "schema" is
not recognized as one. And if you want to use the schema instance
attributes like schemaLocation or noNamespaceSchemaLocation, then you
need to declare the namespace http://www.w3.org/2001/XMLSchema-instance
as well, otherwise they are not recognized as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top