Thanks for the info samtregar maybe you will be kind enough to help me out somemore? Here's what i got going so far ...
bash-2.03$ cat perl_xml_schema.pl #!/usr/local/bin/perl -w use strict; use XML::SAX::ParserFactory; use XML::Validator::Schema; sub usage { return "$0 <xml> <xsd>\n"; } my $xml = shift || die usage; my $xsd = shift || die usage; # # create a new validator object, using foo.xsd # my $validator = XML::Validator::Schema->new(file => $xsd); # # create a SAX parser and assign the validator as a Handler # my $parser = XML::SAX::ParserFactory->parser(Handler => $validator); # # validate foo.xml against foo.xsd # eval { $parser->parse_uri($xml) }; die "File failed validation: $@" if + $@; bash-2.03$ cat XML/invoice.xml <?xml version="1.0"?> <invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="XML/simpleInvoice.xsd"> <invoiceNumber>A1112CD</invoiceNumber> <originator> <companyName>Metaphorical Web</companyName> <companyContact>James Eldridge</companyContact> <companyIdentifier>MetWeb</companyIdentifier> </originator> <receiver> <companyName>Semantic Web</companyName> <companyContact>Sarah Tremaine</companyContact> <companyIdentifier>SemanticWeb</companyIdentifier> </receiver> <lineItems> <lineItem> <itemDescription>Essay on Metaphorical Web</itemDescription> <itemCount>1</itemCount> <itemUnit>Article</itemUnit> <itemPrice currency="USD">155.60</itemPrice> <itemTotal currency="USD">155.60</itemTotal> </lineItem> <lineItem> <itemDescription>Lesson Package </itemDescription> <itemCount>4</itemCount> <itemUnit>Lesson</itemUnit> <itemPrice currency="USD">176.13</itemPrice> <itemTotal currency="USD">704.52</itemTotal> </lineItem> </lineItems> <total>860.12</total> </invoice> bash-2.03$ cat XML/simpleInvoice.xsd <!-- simpleInvoice.xsd --> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="invoiceNumber" type="xsd:string"> </xsd:element> <xsd:element name="originator"> <xsd:complexType> <xsd:sequence> <xsd:element ref="companyName"/> <xsd:element ref="companyContact"/> <xsd:element ref="companyIdentifier"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="companyName" type="xsd:string"> </xsd:element> <xsd:element name="companyContact" type="xsd:string"> </xsd:element> <xsd:element name="companyIdentifier" type="xsd:string"> </xsd:element> <xsd:element name="receiver"> <xsd:complexType> <xsd:sequence> <xsd:element ref="companyName"/> <xsd:element ref="companyContact"/> <xsd:element ref="companyIdentifier"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="itemDescription" type="xsd:string"> </xsd:element> <xsd:element name="itemCount" type="xsd:string"> </xsd:element> <xsd:element name="itemUnit" type="xsd:string"> </xsd:element> <xsd:element name="itemPrice"> <xsd:complexType> <xsd:simpleContent> <xsd:extension base="xsd:string"> <xsd:attribute name="currency" type="xsd:string" use="required"/> </xsd:extension> </xsd:simpleContent> </xsd:complexType> </xsd:element> <xsd:element name="itemTotal"> <xsd:complexType> <xsd:simpleContent> <xsd:extension base="xsd:string"> <xsd:attribute name="currency" type="xsd:string" use="required"/> </xsd:extension> </xsd:simpleContent> </xsd:complexType> </xsd:element> <xsd:element name="lineItem"> <xsd:complexType> <xsd:sequence> <xsd:element ref="itemDescription"/> <xsd:element ref="itemCount"/> <xsd:element ref="itemUnit"/> <xsd:element ref="itemPrice"/> <xsd:element ref="itemTotal"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="lineItems"> <xsd:complexType> <xsd:sequence maxOccurs="unbounded"> <xsd:element ref="lineItem"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="total" type="xsd:string"> </xsd:element> <xsd:element name="invoice"> <xsd:complexType> <xsd:sequence> <xsd:element ref="invoiceNumber"/> <xsd:element ref="originator"/> <xsd:element ref="receiver"/> <xsd:element ref="lineItems"/> <xsd:element ref="total"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
Now when i run my script I get this ...
bash-2.03$ ./perl_xml_schema.pl XML/invoice.xml XML/simpleInvoice.xsd Found element without a name. bash-2.03$ ls -l >junk bash-2.03$ ./perl_xml_schema.pl junk XML/simpleInvoice.xsd Found element without a name.
What's going on here?

Plankton: 1% Evil, 99% Hot Gas.

In reply to Re: Re: Is there any way I can validate XML documents with XML Schema using Perl? by Plankton
in thread Is there any way I can validate XML documents with XML Schema using Perl? by Plankton

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.