 |
| XML General XML discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 7th, 2009, 04:30 AM
|
|
Authorized User
|
|
Join Date: Feb 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Any tool to validate the length of each xml attribute against an xml schema
Hi,
Does anyone know if there is a tool to validate the length of each xml attribute against an xml schema.
By validation i mean is just to validate if the data of an attribute has exceeded a specific length.
Our client system is based on an xml schema.
Our system generates the xml. So if there is any tool, i can generate the xml and validate it against schema which we have , it would be easy to know whether this xml would give an error once it goes to the client system.
Regards,
Leo
|
|

December 7th, 2009, 05:14 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Not sure I follow completely. If the schema has placed restrictions on the attributes such as maxLength then any standard validation will expose problems.
Are you asking if you can just validate attributes but not other nodes?
|
|

December 7th, 2009, 05:27 AM
|
|
Authorized User
|
|
Join Date: Feb 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Suppose i have an xml which has an attribute "Name" for a node Person. In the xml schema the maxlength specified for "Name" is 35.
In case in the xml, the data in the "Name" field is of length 45, the tool should say the length has exceeded.
Is there any tool that does that?
|
|

December 7th, 2009, 05:40 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
>In case in the xml, the data in the "Name" field is of length 45, the tool should say the length has exceeded. Is there any tool that does that?
Every schema validation tool does that. You will find schema validation tools in the XML IDEs such as oXygen, Stylus Studio and XML Spy; in the Java world you can use Xerces or Saxon; in the Microsoft world both the MSXML and .NET parsers will validate an instance against a schema. Of course all these tools will check ALL the constraints in your schema, not just attribute length constraints.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

December 7th, 2009, 01:05 PM
|
|
Registered User
|
|
Join Date: Nov 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How detailed do you want to get?
Quote:
Originally Posted by mhkay
>In case in the xml, the data in the "Name" field is of length 45, the tool should say the length has exceeded. Is there any tool that does that?
Every schema validation tool does that. You will find schema validation tools in the XML IDEs such as oXygen, Stylus Studio and XML Spy; in the Java world you can use Xerces or Saxon; in the Microsoft world both the MSXML and .NET parsers will validate an instance against a schema. Of course all these tools will check ALL the constraints in your schema, not just attribute length constraints.
|
But do those tools give specific enough error messages to indicate that a specific attribute in a specific element has exceeded the maxLength restriction facet? I know the javax.xml.parsers.DocumentBuilderFactory class provides only very vague error handling - breaking errors into three major classifications: warning, error, and fatalError.
LeoMathew, do you want a tool that you must manually run on each document before you load it into your database? Or do you want something to validate and give you more explicit error messages as the data is being read into the database? Do you need to know exactly where the error is or simply that the instance document is non-conforming? All of these questions will help us narrow down what would be the most appropriate "tool" for you to use.
|
|

December 7th, 2009, 01:48 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
>But do those tools give specific enough error messages to indicate that a specific attribute in a specific element has exceeded the maxLength restriction facet?
Why not try them out and see?
Saxon gives this message:
Validation error on line 9 column 45 of test.xml:
FORG0001: Validating test/@value: Value "abcdefghijklmnopqrstuvwxyz" contravenes the
maxLength facet "12" of the type of attribute value (See
http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 3)
If you run the validation from your own application, the various parts of this message are available to your application to process as you like.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

December 8th, 2009, 05:02 AM
|
|
Authorized User
|
|
Join Date: Feb 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Any tool to validate the length of each xml attribute against an xml schema
Yes Grant.I want a tool that you must manually run on each document before you load it into your database.
I am still trying out the tools mentioned by mhkay.
|
|
 |