[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]
Subject: Perl UBL validator - example
David, I probably understand what you are saying now. For now though, I don't have the time. I just need some quick and dirty tests for a production system. Here's a basic example of a validator perl script to cust and paste at home. It's intended to do a very basic check of a UBL purchase order. This was the first cut and serves as an example. (how to use: install perl or use linux cut and paste into checkPO.pl check XPath and XMLParser libraries are installed) to run: perl checkPO.pl <UBL-purchase-order-file> Usual disclaimers apply. ---- start #/usr/bin/perl # # -- Computergrid UBL Purchase Order Validator # (c) Global Tradedesk Technology (Australia) Pty Limited 2004 # -- Free for educational use # use XML::XPath; use XML::XPath::XMLParser; print "Computergrid.net - UBL PO Document Test Script\n"; # -- create an object to parse the file and field XPath queries my $xpath = XML::XPath->new( filename => shift @ARGV ); # -- print ".Checking Header for mandatory fields\n"; my @checkElems; my $FailCount = 0; # -- apply the path from the command line and get back a list matches #my $nodeset = $xpath->find( shift @ARGV ); push (@checkElems,"/Order/cat:IssueDate"); push (@checkElems,"/Order/cat:BuyersID"); push (@checkElems,"/Order/cat:SellersID"); push (@checkElems,"/Order/cat:LineExtensionTotalAmount"); push (@checkElems,"/Order/cat:LineItemCountQuantity"); push (@checkElems,"/Order/cat:BuyerParty/cat:SellerAssignedAccountID"); push (@checkElems,"/Order/cat:OrderLine\[1\]"); push (@checkElems,"/Order/cat:OrderLine\[1\]/cat:LineItem/cat:Quantity"); push (@checkElems,"/Order/cat:OrderLine\[1\]/cat:LineItem/cat:LineExtensionAmount"); push (@checkElems,"/Order/cat:OrderLine\[1\]/cat:LineItem/cat:Item/cat:Description"); push (@checkElems,"/Order/cat:OrderLine\[1\]/cat:LineItem/cat:Item/cat:SellersItemIdentification/cat:ID"); #push (@checkElems,"/Order/cat:OrderLine\[1\]/cat:LineItem/cat:Item/cat:BasePrice"); # -- Now loop through each of the elements to validate and check their existance foreach my $elem (@checkElems) { if ($xpath->exists($elem)){ my $nodeset = $xpath->find($elem); print " ..\[Exists\] $elem\n"; } else { print " ..\[Not Exists\] $elem \n"; $FailCount = $FailCount + 1; } } if ($FailCount eq 0){ print "[Pass] Document passed Validatation test\n"; } else { print "[Fail] Document failed Validatation test with $FailCount Errors\n"; } ---- end Quoting David RR Webber <david@drrw.info>: > David, > > The only thing I'd add to Jon's comments is - why re-invent the wheel? > > OASIS already has the CAM specification in place - you are most welcome to > integrate the concepts and techniques from that work - and there's even the > open source implementaton to help you. > > There is certainly a perfect opportunity from the business stance to create > a > shareware product that provides cool end-user tools to manipulate rules and > UBL > structures and express those in CAM templates as XML... > > If you look at the CAM Wizard HTML and Javascript that's in the tutorial > available from the OASIS CAM site - you may get even more ideas of how you > could embed UBL structures into an online Wizard - and then allows you to > click > and choose - and build your rules sets. Just some ideas. > > This would make a very nice shareware product that would be easy to > implement > IMHO. Oh - yep - you can write it in Perl too if you want too - no > objections > there! > > Cheers, DW. > ============================================================ > > Quoting jon.bosak@sun.com: > > > [david.lyon@computergrid.net:] > > > > | We are in the middle of producing a UBL validator/testpad so we > > | haven't made it publicly available yet. > > | > > | It's written in Perl and does a wide variety of tests on > > | documents. The basic idea is that it would be able to scrutinise a > > | trading partners documents for compliance to the specifications. > > | > > | Our plan is to release the tool as shareware in the next month or > > | so. > > > > David, > > > > This is exactly the kind of tool we need to make UBL practical, > > and I'm glad to see the ubl-dev list beginning to function as a > > place for sharing this sort of information. As your examples > > show, real-life applications need to do a lot of "business > > validation" beyond the "schema validation" provided by the UBL > > schemas. It will be interesting to see the various approaches > > that emerge to accomplish this. > > > > | If anything, UBL needs way more tools from way more people than > > | it has. > > > > I completely agree. The more, the better. > > > > | and I sometimes get the impression that there is a lot of > > | negative encouragement given to anybody outside of the > > | oasis banner, as if to say, leave it to the big boys, we'll > > | take care of it. Whatever.... > > > > Please don't take the comments of any particular OASIS participant > > as reflecting the organization as a whole. OASIS has one of the > > least hierarchical organizational structures of any major > > standards body, and no chair of an OASIS TC speaks for any other > > TC. I can assure you as the chair of the UBL TC that we are > > wholeheartedly supportive of efforts such as yours, and I applaud > > the shareware approach you're planning to adopt for distribution > > of your product. > > > > | UBL and ebxml is struggling... can't see why.... > > > > UBL and ebXML are both continuing to steadily gain traction in the > > face of heavy opposition from certain Very Large American Software > > Companies. Those of us who were privileged to watch the early > > "grass roots" stages of Web adoption can see some basic > > similarities here. Just as in the case of the web, homegrown > > products such as yours will play an essential role in deploying > > these user-oriented technologies. Keep up the good work! > > > > Jon > > > > > > > http://drrw.net > -------------------------------------------------------
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]