469,306 Members | 1,797 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

perl Validator for XML

Hi ,
I am using the perl validator program given at CPAN for validation of xml
(.xml) against XML schema(.xsd).

The validator program is working fine with all modules installed correctly.
I checked it with many examples.

But now I am using the "group" element of XML schema, in schema file, and
I am getting error given below,

unrecognized element '<group>' found.
Oct 3 '07 #1
11 4555
numberwhun
3,503 Expert Mod 2GB
Hi ,
I am using the perl validator program given at CPAN for validation of xml
(.xml) against XML schema(.xsd).

The validator program is working fine with all modules installed correctly.
I checked it with many examples.

But now I am using the "group" element of XML schema, in schema file, and
I am getting error given below,

unrecognized element '<group>' found.
Could you please post your code(in code tags), the name of the module you are using for validation, and a sample of the data (including the offending element)?

Thanks!

Regards,

Jeff
Oct 3 '07 #2
At the start, i.e at line given below in perl file the error is occuring,
$validator = XML::Validator::Schema->new(file => '/xml2c/test1/test_1.xsd');

The error is written in file given below,
package XML::Validator::Schema::Parser;

where there is no check for "group" element ..
So at the last else loop the parser is failed with the error mentioned above ..


The perl validator program file is :
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use XML::SAX::ParserFactory;
  3.   use XML::Validator::Schema;
  4.  
  5.   #
  6.   # create a new validator object, using foo.xsd
  7.   #
  8.   $validator = XML::Validator::Schema->new(file => '/xml2c/test1/test_1.xsd');
  9.  
  10.   #
  11.   # create a SAX parser and assign the validator as a Handler
  12.   #
  13.   $parser = XML::SAX::ParserFactory->parser(Handler => $validator);
  14.  
  15.   #
  16.   # validate foo.xml against foo.xsd
  17.   #
  18.   eval { $parser->parse_uri('/xml2c/test1/test_schema_1.xml') };
  19.   if ($@) {
  20.     die "File failed validation: $@";
  21.   } else {
  22.     print "Validation completed without error";
  23.  
.xsd file
Expand|Select|Wrap|Line Numbers
  1. <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  2.    <xsd:element name="PurchaseOrderType">
  3.       <xsd:complexType>
  4.          <xsd:sequence>
  5.             <xsd:choice>
  6.                <xsd:group ref="shipAndBill"/>
  7.                <xsd:element name="singleUSAddress" type="USAddress"/>
  8.             </xsd:choice>
  9.             <xsd:element ref="comment" minOccurs="0"/>
  10.             <xsd:element name="items" type="Items"/>
  11.          </xsd:sequence>
  12.          <xsd:attribute name="orderDate" type="xsd:date"/>
  13.       </xsd:complexType>
  14.    </xsd:element>
  15.    <xsd:complexType name="USAddress">
  16.    <xsd:sequence>
  17.       <xsd:element name="name" type="xsd:string"/>
  18.       <xsd:element name="street" type="xsd:string"/>
  19.       <xsd:element name="city" type="xsd:string"/>
  20.       <xsd:element name="state" type="xsd:string"/>
  21.       <xsd:element name="zip" type="xsd:decimal"/>
  22.    </xsd:sequence>
  23.    <xsd:complexType name="Items">
  24.       <xsd:sequence>
  25.          <xsd:element name="item" minOccurs="0" maxOccurs="unbounded">
  26.             <xsd:complexType>
  27.                <xsd:sequence>
  28.                   <xsd:element name="productName" type="xsd:string"/>
  29.                   <xsd:element name="quantity">
  30.                      <xsd:simpleType>
  31.                         <xsd:restriction base="xsd:positiveInteger">
  32.                            <xsd:maxExclusive value="100"/>
  33.                         </xsd:restriction>
  34.                      </xsd:simpleType>
  35.                   </xsd:element>
  36.                   <xsd:element name="USPrice" type="xsd:decimal"/>
  37.                   <xsd:element ref="comment" minOccurs="0"/>
  38.                   <xsd:element name="shipDate" type="xsd:date" minOccurs="0"/>
  39.                </xsd:sequence>
  40.                <xsd:attribute name="partNum" type="SKU" use="required"/>
  41.             </xsd:complexType>
  42.          </xsd:element>
  43.       </xsd:sequence>
  44.    </xsd:complexType>
  45.    <xsd:group id="shipAndBill">
  46.       <xsd:sequence>
  47.          <xsd:element name="shipTo" type="USAddress"/>
  48.          <xsd:element name="billTo" type="USAddress"/>
  49.       </xsd:sequence>
  50.    </xsd:group>
  51. </xsd:schema>
  52.  
.xml file
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <purchaseOrder orderDate="1999-10-20">
  3.    <shipTo country="US">
  4.       <name>Alice Smith</name>
  5.       <street>123 Maple Street</street>
  6.       <city>Mill Valley</city>
  7.       <state>CA</state>
  8.       <zip>90952</zip>
  9.    </shipTo>
  10.    <billTo country="US">
  11.       <name>Robert Smith</name>
  12.       <street>8 Oak Avenue</street>
  13.       <city>Old Town</city>
  14.       <state>PA</state>
  15.       <zip>95819</zip>
  16.    </billTo>
  17.    <comment>Hurry, my lawn is going wild<!/comment>
  18.    <items>
  19.       <item partNum="872-AA">
  20.          <productName>Lawnmower</productName>
  21.          <quantity>1</quantity>
  22.          <USPrice>148.95</USPrice>
  23.          <comment>Confirm this is electric</comment>
  24.       </item>
  25.       <item partNum="926-AA">
  26.          <productName>Baby Monitor</productName>
  27.          <quantity>1</quantity>
  28.          <USPrice>39.98</USPrice>
  29.          <shipDate>1999-05-21</shipDate>
  30.       </item>
  31.    </items>
  32. </purchaseOrder>
  33.  
Oct 3 '07 #3
Hi Jeff,
Could you help me solving this error.

Thank you.

-Abhijeet
Oct 4 '07 #4
The parser.pm for schema handling does not have entry for how to handle a "group" element. So it exits by throwing an error after compairing with all the available cases (complexType, Documentation etc ...).

Is it necessary to update parser.pm to handle group element.
Oct 4 '07 #5
numberwhun
3,503 Expert Mod 2GB
Hi Jeff,
Could you help me solving this error.

Thank you.

-Abhijeet
Thank you for posting your code and data sample(s). Hopefully one of the Experts here will have an answer for you or some guidance.

Please know though that when you post code, you REALLY need to apply code tags around your code. The "REPLY GUIDELINES" to the right of your Message window when replying provides an example of code tags. Please use them for all future code postings in your messages.

Regards,

Jeff
Oct 4 '07 #6
Thank you for your guidelines to post the code on forum. I will surely use those in future postings.


-Abhijeet
Oct 4 '07 #7
According to me it's a bug in XML-Validator-Schema that it not supports <group> tag.
Oct 4 '07 #8
numberwhun
3,503 Expert Mod 2GB
According to me it's a bug in XML-Validator-Schema that it not supports <group> tag.
I wish I could provide you an answer, but I unfortunately am no really versed yet in XML nor the module you are using.

Hopefully there is an Expert on hand that has experience with it and that can help.

Regards,

Jeff
Oct 4 '07 #9
eWish
971 Expert 512MB
I would suggest that you try to validate your code via another source. Once it validates correctly, then try the module. This will tell you if the problem is in the module or your xml.

W3Schools Validate XML

Just a thought.
Oct 4 '07 #10
numberwhun
3,503 Expert Mod 2GB
I would suggest that you try to validate your code via another source. Once it validates correctly, then try the module. This will tell you if the problem is in the module or your xml.

W3Schools Validate XML

Just a thought.
In continuing with validation suggestions, if you go to Google (wonderful search engine that it is) and search for "free xml validator", the first link that comes up is for Altova XML.

Considering that they are the makers of XML Spy, which is an excellent XML program, I would say that that is probably a good product to try. And best of all, its FREE.

Regards,

Jeff
Oct 4 '07 #11
Thank you all for your suggestions.

XML schema feature "group" is not supported in XML::Validator::Schema.
That's why I was getting the error, now I am trying to implement that feature in module.

But simultaneously I am going with the solutions provided by all.

Will update you soon.

Thank you again.

-Abhijeet
Oct 5 '07 #12

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

195 posts views Thread by Torbjørn Pettersen | last post: by
reply views Thread by Tom Pearson | last post: by
1 post views Thread by qwelk179 | last post: by
9 posts views Thread by Julia De Silva | last post: by
40 posts views Thread by VK | last post: by
2 posts views Thread by Mike Collins | last post: by
1 post views Thread by Gonza | last post: by
37 posts views Thread by Prisoner at War | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.