XML based on XSD

gudii9
gudii9 used Ask the Experts™
on
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.gp.com/Patient"
	xmlns:tns="http://www.gp.com/Patient" elementFormDefault="qualified">

	<element name="patient" type="tns:Patient" />

	<complexType name="Patient">

		<sequence>
			<element name="id" type="tns:ID" />
			<element name="name" type="tns:string15chars" />
			<element name="age" type="int" />
			<element name="dob" type="date" />
			<element name="email" type="string" />
			<element name="gender" type="tns:genderEnum" />
			<element name="phone" type="string" />

		</sequence>

	</complexType>

	<simpleType name="ID">
		<restriction base="int">
			<pattern value="[0-9]*"></pattern>
		</restriction>
	</simpleType>

	<simpleType name="string15chars">
		<restriction base="string">
			<pattern value="15"></pattern>
		</restriction>
	</simpleType>



	<simpleType name="genderEnum">
		<restriction base="string">
			<enumeration value="M"/>
			<enumeration value="F"/>
		</restriction>
	</simpleType>


</schema>

Open in new window


Based on aboveXSD i generated below XML which gives error at line 4 of XML as
Multiple annotations found at this line:
      - cvc-type.3.1.3: The value 'Maaa' of element 'tns:name' is not valid.
      - cvc-pattern-valid: Value 'Maaa' is not facet-valid with respect to pattern '15' for type
       'string15chars'.


<?xml version="1.0" encoding="UTF-8"?>
<tns:patient xmlns:tns="http://www.gp.com/Patient" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.gp.com/Patient Patient.xsd ">
  <tns:id>1</tns:id>
  <tns:name>Maaa</tns:name>
  <tns:age>0</tns:age>
  <tns:dob>2001-01-01</tns:dob>
  <tns:email>tns:email</tns:email>
  <tns:gender>M</tns:gender>
  <tns:phone>tns:phone</tns:phone>
</tns:patient>

Open in new window



why i am getitng this error and how to fix it. i using eclipse for this as IDE.
any other open source XML IDEs bettr than eclipse to work on these simple xml, XSDs etc
please advise
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Gertone (Geert Bormans)Information Architect
Top Expert 2006
Commented:
<element name="name" type="tns:string15chars" />
indicates that tns:name should have a simple type of this definition tns:string15chars
that type is defined as a string restriction facet pattern <pattern value="15"></pattern>
inside @value is a regex that should match the value of tns:name
I assume you are using the wrong facet
the only string that matches the regex "15" is the string "15"
the only legal value of tns:name is <tns:name>15</tns:name>
that is likely not what you want

If you want to allow up to 15 characters, you might want to change the pattern
<pattern value="[a-zA-Z0-9]{1 to 15}"></pattern>
Information Architect
Top Expert 2006
Commented:
I missed the syntax actually

better example
    <simpleType name="string15chars">
        <restriction base="string">
            <pattern value="[a-zA-Z0-9]{1,15}"></pattern>
        </restriction>
    </simpleType>

Open in new window

Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
it is all there, complete and correct, lacking feedback sadly

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial