Jump to content
sam.surya

xml schema validation

Recommended Posts

Hi,I'm new to schema writing. I have xml doc. like this-----------------------------------------------------------------XML Doc: <?xml version="1.0" encoding="UTF-8"?><Assets><TOCNode><PackageName></PackageName> <NodeName></NodeName></TOCNode><Text><name></name><TextData>- <![CDATA[]]></TextData></Text><Quiz><name></name><Question><Text><name></name><TextData>- <![CDATA[]]></TextData></Text><Text><name></name><TextData>- <![CDATA[]]></TextData></Text><Answer correct="true"><Text><name></name><TextData>- <![CDATA[]]></TextData></Text></Answer><Answer correct="false"><Text><name></name><TextData>- <![CDATA[]]></TextData></Text></Answer></Question></Quiz></Assets>---------------------------------------------------------------xml schema<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="Assets" type="xs:string"> <xs:element name="Text" type="xs:string"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="TextData" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType> <xs:sequence> <xs:element name="TOCNode" type="xs:string"> <xs:complexType> <xs:sequence> <xs:element name="PackageName" type="xs:string"/> <xs:element name="NodeName" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Quiz" type="xs:string"> <xs:complexType> <xs:sequence> <xs:element name="Name" type="xs:string"/> <xs:element name="Question" type="xs:string"> <xs:complexType> <xs:sequence><xs:element name="Text" type="xs:string"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="TextData" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Answer" type="xs:string"> <xs:complexType> <xs:sequence> <xs:element name="Text" type="xs:string"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="TextData" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="correct" type="xs:string" use="required"/> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>-------------------------------------------Please help me for the right schema...Thanks in advancekamal

Share this post


Link to post
Share on other sites

What exactly is the problem?

Share this post


Link to post
Share on other sites

Your XML file should validate against this schema. You may need to change the minOccurs and maxOccurs of the Answer element, depending on if that's how many times that element appears in every XML file.

<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">	<!-- Simple types -->	<xs:simpleType name="nameType">		<xs:restriction base="xs:string"/>	</xs:simpleType>		<!-- Complex types -->	<xs:complexType name="tocNodeType">		<xs:sequence>			<xs:element name="PackageName" type="xs:string"/>			<xs:element name="NodeName" type="xs:string"/>		</xs:sequence>	</xs:complexType>			<xs:complexType name="textType">		<xs:sequence>			<xs:element name="name" type="nameType"/>			<xs:element name="TextData" type="xs:string"/>		</xs:sequence>	</xs:complexType>		<xs:complexType name="answerType">		<xs:sequence>			<xs:element name="Text" type="textType"/>		</xs:sequence>		<xs:attribute name="correct" type="xs:boolean"/>	</xs:complexType>		<xs:complexType name="questionType">		<xs:sequence>			<xs:element name="Text" type="textType" maxOccurs="2"/>			<xs:element name="Answer" type="answerType" minOccurs="2" maxOccurs="2"/>		</xs:sequence>	</xs:complexType>		<xs:complexType name="quizType">		<xs:sequence>			<xs:element name="name" type="xs:string"/>			<xs:element name="Question" type="questionType"/>		</xs:sequence>	</xs:complexType>		<!-- Main complex type -->	<xs:complexType name="assetType">		<xs:sequence>			<xs:element name="TOCNode" type="tocNodeType"/>			<xs:element name="Text" type="textType"/>			<xs:element name="Quiz" type="quizType"/>		</xs:sequence>	</xs:complexType>		<!-- Root element -->	<xs:element name="Assets" type="assetType"/></xs:schema>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...