Hi, I test a simple data modele of which the schema is : <xsd:complexType name="PersonType"> <xsd:sequence> <xsd:element type="PersonId" name="id"/> <xsd:element name="name" type="xsd:string"/> </xsd:sequence> </xsd:complexType>

<xsd:simpleType name="PersonId">
  <xsd:annotation>
      <xsd:documentation>
      Define identification of a Person
      </xsd:documentation>
  </xsd:annotation>
  <xsd:restriction base="xsd:string">
      <xsd:pattern value="(\p{L}|_)+:\p{L}+:[0-9A-Za-z]+"/>
  </xsd:restriction>
</xsd:simpleType>

I've generated classes from that schema by castor. Now in my principal program, I try to marshall that object into a xml file:
Person aPerson = new Person();
aPerson.setName("Tuan Anh");
aPerson.setId("Hello:Hello:123");
Marshaller marshaller = new Marshaller(new FileWriter("person1.xml"));
marshaller.setEncoding( "UTF-8");
marshaller.setNamespaceMapping( "xsi", Marshaller.XSI_NAMESPACE);
marshaller.marshal(aPerson);


And I receive the following Exception while marshalling the object:
Exception in thread "main" ValidationException: objects of this type must match the following regular expression: (\p{L}|_)+:\p{L}+:[0-9A-Za-z]+;
- location of error: XPATH: Person
Eventhough I've respected the pattern


I've tried the pattern with regex of java, it works:
Pattern pattern = Pattern.compile("(\\p{L}|_)+:\\p{L}+:[0-9A-Za-z]+");
Matcher matcher = pattern.matcher("Hello:Hello:123");
System.out.println(matcher.find());

Output:
true

I've created myself a xml document which contains a Person with the same Id and have it validated by the schema

Anyone has an idea?
Thanks
Tuan Anh



----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user

Reply via email to