Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validating Schema errors

Status
Not open for further replies.

270679

Programmer
Mar 10, 2004
1
0
0
DK
Hi
I'am trying to validate my schema in xerces. However, I get the following errors. Can anybody help me solve them:

[Error] ITUblog.xsd:89:26: src-resolve.4: Components from namespace ' are not referenceable from schema document 'file:///C:/xerces/ITUblog.xsd'.
[Error] blog.xml:26:15: cvc-complex-type.2.4.a: Invalid content starting with element 'author'. The content must match '(EMPTY,EMPTY,EMPTY)'.
[Error] blog.xml:28:13: cvc-complex-type.2.4.a: Invalid content starting with element 'text'. The content must match '(EMPTY,EMPTY,EMPTY)'.
[Error] blog.xml:40:15: cvc-complex-type.2.4.a: Invalid content starting with element 'author'. The content must match '(EMPTY,EMPTY,EMPTY)'.
[Error] blog.xml:42:13: cvc-complex-type.2.4.a: Invalid content starting with element 'text'. The content must match '(EMPTY,EMPTY,EMPTY)'.

Here is my author definition:
<element name="author">
<complexType mixed="true">
<sequence>
<element name="name" minOccurs="0" maxOccurs="1"/>
<element name="email" minOccurs="0" maxOccurs="1"/>
</sequence>
</complexType>
</element>

My problem is that the author element either can be a simple element with only text or an element with only other elements inside it. How do I define that!

Thanks for any help
Rasmus
 
This might be one solution, although not exactly what you had specified.


author.xsd file

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] elementFormDefault="qualified" attributeFormDefault="unqualified">
 <xs:element name="root">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="authors" maxOccurs="unbounded">
     <xs:complexType>
      <xs:choice>
       <xs:element name="author" type="xs:string"/>
       <xs:sequence>
        <xs:element name="name" type="xs:string" minOccurs="0"/>
        <xs:element name="email" type="xs:string" minOccurs="0"/>
       </xs:sequence>
      </xs:choice>
     </xs:complexType>
    </xs:element>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>

Sample XML file

Code:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xsi:noNamespaceSchemaLocation="C:\add your path here\author.xsd">
	<authors>
		<author> Fred blogs</author>
	</authors>
	<authors>
		<name>This is a name</name>
		<email>name@somewhere.com</email>
	</authors>
	<authors>
		<author>Ivor Book</author>
	</authors>
</root>

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top