Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: regex help

From: "Watkins, Bill" <bill.watkins@------.--->
To: <xmlschema-dev@--.--->
Date: 1/4/2007 11:01:00 AM
Thanks to Michael Kay and Xan Gregg for proposing solutions to the
problem of not being able to use the non-greedy regex quantifiers in the
pattern facet when trying to validate something like a list of delimited
strings (in this case, the delimiter is a double-quote).  Unfortunately,
I'm still unable to validate an element that contains a list of quoted
strings with the suggested patterns.  Below are my results using the
various suggestions.

I'm using the XML-Buddy 2.0.9 plug-in to Eclipse 3.2.1 for validation.
Interestingly, some of the pattern regex's will pass the strings so long
as they don't contain an embedded whitespace character.  I've included
test results using both strings.

The "free" version of XML-Buddy only seems to provide mouse-over
validation error pop-ups.  Note that validation engine sometimes
returned a different error message in the pop-up in some cases on
successive tries.  In these cases, one of two errors was typically
returned in the mouse-over message, either one pointing at the pattern
facet for the element type, or one pointing at the element.  I don't
know why this happens, though it might be something like a hash table
query resulting in different retrieval orders on the mouse-over.

Sample test file:


<?xml version="1.0"?>
<TestSmall xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="TestSmallQuotedListSchema.xml">
=09
	<QuotedStringList>
		"your dog.my_dog" "my_cat$your_cat"
		"their_rat"
	</QuotedStringList>
=09
</TestSmall>

Sample test file:


<?xml version="1.0"?>
<TestSmall xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="TestSmallQuotedListSchema.xml">
=09
	<QuotedStringList>
		"your dog.my_dog" "my_cat$your_cat"
		"their_rat"
	</QuotedStringList>
=09
</TestSmall>


Original schema candidate (i.e., mine):



<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">

	<xs:simpleType name="QUOTEDNAME_TYPE">
		<xs:restriction base="xs:string">
			<xs:pattern value='\s*"\S([^"]|\s)+\S"\s*'/>
		</xs:restriction>
	</xs:simpleType>
=09
	<xs:simpleType name="QUOTEDNAMELIST_TYPE">
		<xs:list itemType="QUOTEDNAME_TYPE"/>		=09
	</xs:simpleType>
=09
	<xs:element name="QuotedStringList" type="QUOTEDNAMELIST_TYPE"/>
=09
	<xs:element name="TestSmall">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="QuotedStringList"
minOccurs="1" maxOccurs ="1"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>

</xs:schema>



Validation Result w/o underscore ("your dog"):
"Error -cvc-pattern-valid: Value '"your' is not facet-valid with respect
to pattern '\s*"\S([^"]|[\s)+|S"\s*'  for type 'QUOTEDNAME_TYPE'."
OR
"Error -cvc-type.3.1.3: The value "your dog.my_dog" "my_cat$your_cat"
"their_rat" of element 'QuotedStringList'  is not valid.


Validation Result w/ underscore ("your_dog"):
OK

First suggested candidate from Kay:


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">

	<xs:simpleType name="quotedString">
	  <xs:restriction base="xs:string">
		<xs:pattern value='".*"'/>
	  </xs:restriction>
	</xs:simpleType>
=09
	<xs:simpleType name="listOfQuotedStrings">
	  <xs:list itemType="quotedString"/>
	</xs:simpleType>
=09
	<xs:element name="QuotedStringList" type="listOfQuotedStrings"/>
=09
	<xs:element name="TestSmall">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="QuotedStringList"
minOccurs="1" maxOccurs ="1"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>

</xs:schema>



Validation Result w/o underscore ("your dog"):
"Error - cvc-pattern-valid: Value '"your' is not facet-valid with
respect to pattern '".*" for type  'quotedString'.
(Note: it is not entirely clear on my monitor in this case whether the
characters in the  message that look like: '" is actually a single
double-quote with an artifact that appears to be a third  stroke.)
OR
"Error -cvc-type.3.1.3: The value "your dog.my_dog" "my_cat$your_cat"
"their_rat" of element 'QuotedStringList'  is not valid."

Validation Result w/ underscore ("your_dog"):
OK


Alternate suggested candidate from Kay:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">

	<xs:simpleType name="listOfQuotedStrings">
	  <xs:restriction base="xs:string">
		<xs:pattern value='(("[^"]*")\s+)*'/>
	  </xs:restriction>
	</xs:simpleType>
=09
	<xs:element name="QuotedStringList" type="listOfQuotedStrings"/>
=09
	<xs:element name="TestSmall">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="QuotedStringList"
minOccurs="1" maxOccurs ="1"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>

</xs:schema>


Validation Result w/o underscore ("your dog"):
"Error - cvc-pattern-valid: Value '"your dog.my_dog" "my_cat$your_cat"
"their_rat" is not facet-valid with  respect to pattern
'(("[^"]*")\s+)*' for type 'listOfQuotedStrings'."
OR
"Error - cvc-type.3.1.3: The value '"your dog.my_dog" "my_cat$your_cat"
"their_rat" of element  'QuotedStringList' is not valid."

Validation Result w/ underscore ("your_dog"):
"Error - cvc-pattern-valid: Value '"your_dog.my_dog" "my_cat$your_cat"
"their_rat" is not facet-valid with  respect to pattern
'(("[^"]*")\s+)*' for type 'listOfQuotedStrings'."
OR
"Error - cvc-type.3.1.3: The value '"your_dog.my_dog" "my_cat$your_cat"
"their_rat" of element  'QuotedStringList' is not valid."


Suggested revision of Kay's alternate candidate by Xan Gregg:


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">

	<xs:simpleType name="listOfQuotedStrings">
	  <xs:restriction base="xs:string">
		<xs:pattern value='("[^"]*"(\s+"[^"]*")*)?'/>
	  </xs:restriction>
	</xs:simpleType>
=09
	<xs:element name="QuotedStringList" type="listOfQuotedStrings"/>
=09
	<xs:element name="TestSmall">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="QuotedStringList"
minOccurs="1" maxOccurs ="1"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>

</xs:schema>


Validation Result w/o underscore ("your dog"):
"Error - cvc-type.3.1.3: The value '"your dog.my_dog" "my_cat$your_cat"
"their_rat" of element  'QuotedStringList' is not valid.
OR
"Error - cvc-pattern-valid: Value '"your dog.my_dog" "my_cat$"
"their_rat"' is not facet-valid with respect to  pattern
'("[^"]*"(\s+"[^"]*")*)?' for type 'listOfQuotedStrings'.

Validation Result w/ underscore ("your_dog"):
"Error - cvc-pattern-valid: Value '"your_dog.my_dog" "my_cat$your_cat"
"their_rat"' is not facet-valid with  respect to pattern
'(*[^"]*"(\s+"[^"]*")*)?' for type 'listOfQuotedStrings'."
OR 
"Error - cvc-type.3.1.3: The value '"your_dog.my_dog" "my_cat$your_cat"
"their_rat" of element  'QuotedStringList' is not valid.



If anyone has any suggestions, I'd appreciate them.

Thanks,
Bill

Bill Watkins
Software Engineer
Boeing Satellite Operations & Ground Systems - Houston

"Any opinions expressed are my own and do not reflect those of Boeing."
"For every complex problem, there is a solution that is simple, neat,
and wrong."  HL Mencken



From petexmldev@t... Fri Jan 05 08:29:56 2007
Rec


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent