Please help, I am having trouble with getNodeValue(). It won't return anything.
Xerces 1.7.0 Perl Xerces 1.7.0-1 Perl 5.6.1 Linux kernel 2.4.8 (Linux From Scratch distribution) gcc 2.95.3 See toolx line 79 - I can't get any value for size even though I am settine one in ss4.xml. P.S. Thanks for the great work on this project. Although the documentation and samples are a little light, I am so pleased to have a robust Perl implementation for learning to use XML, DOM, etc. Your efforts are very much appreciated! P.P.S. I get lots of error 5's in the tests but ignored them. Example: t/DOMPrint..........ok t/DOM_Attr..........ok t/DOM_DOMException..ok t/DOM_Document......ok 164/35125Error code: 5 t/DOM_Document......ok 661/35125Error code: 5 t/DOM_Document......NOK 662Error code: 5 t/DOM_Document......NOK 663Error code: 5 t/DOM_Document......NOK 664Error code: 5 t/DOM_Document......NOK 665Error code: 5 t/DOM_Document......NOK 666Error code: 5 ...
<!-- Document Type Defintion for the Form_Genie language --> <!-- Global defines --> <!ENTITY % plain_text '#PCDATA'> <!ENTITY % styled_text '#PCDATA | b | i | para'> <!ELEMENT b ( %plain_text;) > <!ELEMENT i ( %plain_text;) > <!ELEMENT para EMPTY> <!ELEMENT form_genie ( datastructure, form+)> <!ELEMENT datastructure ( field* )> <!ELEMENT field ( size, seqno? )> <!ATTLIST field id ID #REQUIRED type ( char | ein | email | numeric | password | ssn ) "char" key ( primary | secondary | none ) "none"> <!ELEMENT size ( %plain_text; )> <!ELEMENT seqno ( %plain_text; )> <!ELEMENT form ( title, faq?, content )> <!ATTLIST form id ID #REQUIRED hidden ( yes | no ) "no"> <!ELEMENT title ( %plain_text; )> <!ELEMENT faq ( entry+ )> <!ELEMENT entry ( question, answer )> <!ELEMENT question ( %styled_text; )*> <!ELEMENT answer ( %styled_text; )*> <!ELEMENT content ( %plain_text; | input | submit )* > <!ELEMENT input ( prompt, mandatory? )> <!ATTLIST input fieldref IDREF #REQUIRED> <!ELEMENT prompt ( %styled_text; )*> <!ELEMENT mandatory EMPTY> <!ELEMENT submit ( label, target )> <!ELEMENT label ( %plain_text; )> <!ELEMENT target ( %plain_text; )> <!ATTLIST target formref IDREF #REQUIRED>
<?xml version="1.0"?> <!DOCTYPE form_genie PUBLIC "-//BHENT//Form Genie V 0.1//EN" "form_genie.dtd"> <form_genie> <!-- ================================================= --> <!-- Data structures --> <!-- ================================================= --> <datastructure> <field id="ss4.main.email" type="email" key="primary"> <size>40</size> <seqno>Testing</seqno> </field> <field id="ss4.main.password" type="password"> <size>10</size> </field> <field id="ss4.main.legal_name" type="char"> <size>40</size> </field> <field id="ss4.main.trade_name" type="char"> <size>40</size> </field> <field id="ss4.main.address1" type="char"> <size>40</size> </field> <field id="ss4.main.address1_csz" type="char"> <size>40</size> </field> <field id="ss4.main.address2" type="char"> <size>40</size> </field> <field id="ss4.main.address2_csz" type="char"> <size>40</size> </field> <field id="ss4.main.county" type="char"> <size>20</size> </field> </datastructure> <!-- ================================================= --> <!-- Introduction --> <!-- ================================================= --> <form id="intro"> <title>IRS Tax ID Number Application</title> <faq> <entry> <question>How much does it cost</question> <answer>You may use the form at no cost. If you would like to print or have your completed application faxed to the IRS, the charge is $9 </answer> </entry> <entry> <question>How long does it take</question> <answer>The average time to fill out our online application is 10 minutes. Once complete, you may proceed to call IRS's TELE-TIN number to obtain your EIN immediately (during normal business hours). If you are applying on a holiday or weekend or prefer not to call the IRS, you can request that we fax your application to IRS and you can expect a response within 4 business days. </answer> </entry> </faq> <content> This form will guide you through the process of applying for an IRS Federal Tax ID number. The process takes about 10 minutes and once complete, the IRS will usually issue your Tax ID Number within 1 to 4 business days. <submit> <label>Next</label> <target formref="login"/> </submit> <submit> <label>Cancel</label> <target formref="f99_cancel"/> </submit> </content> </form> <!-- ================================================= --> <!-- How does user want to login (new or returning) --> <!-- ================================================= --> <form id="login"> <title>Are You a Returning User</title> <faq> <entry> <question>What if I cannot remember if I've used this system before</question> <answer>Choose <b>No</b> below. We will ask for your e-mail address and if you've visited us before, you'll be directed to the login page </answer> </entry> </faq> <content> Are you a returning user? <submit> <label>Yes</label> <target formref="login_returning"/> </submit> <submit> <label>No</label> <target formref="login_new"/> </submit> </content> </form> <!-- ================================================= --> <!-- New user login --> <!-- ================================================= --> <form id="login_new"> <title>Are You a New User</title> <faq> <entry> <question>How is my e-mail address used?</question> <answer>Your e-mail address is used to store your SS-4 application, communicate with you about its status, and allow you to login in at a later time to make modifications or check on its status. We will never share your e-mail address with IRS or any third parties. </answer> </entry> </faq> <content> To begin your SS-4 application, please enter your e-mail address and choose a password. <input fieldref="ss4.main.email"> <prompt>Enter your e-mail address</prompt> <mandatory/> </input> <input fieldref="ss4.main.password"> <prompt>Enter your password</prompt> <mandatory/> </input> <submit> <label>Next</label> <target formref="f1_legal_name"/> </submit> <submit> <label>Previous</label> <target formref="login"/> </submit> </content> </form> <!-- ================================================= --> <!-- Returning user login --> <!-- ================================================= --> <form id="login_returning"> <title>Are You a New User</title> <faq> <entry> <question>What if I have forgotten my password</question> <answer>You can have your password e-mailed to you</answer> </entry> </faq> <content> To retrieve an SS-4 application that you have already started, please provide your e-mail address and password. <input fieldref="ss4.main.email"> <prompt>Enter your e-mail address</prompt> <mandatory/> </input> <input fieldref="ss4.main.password"> <prompt>Choose a password</prompt> <mandatory/> </input> <submit> <label>Next</label> <target formref="f1_legal_name"/> </submit> <submit> <label>Previous</label> <target formref="login"/> </submit> </content> </form> <!-- ================================================= --> <!-- 1 - Legal name --> <!-- ================================================= --> <form id="f1_legal_name"> <title>Legal Name</title> <content> Legal name of entity (or individual) for whom the EIN is being requested. <input fieldref="ss4.main.legal_name"> <prompt>Legal name</prompt> <mandatory/> </input> <submit> <label>Next</label> <target formref="f2_trade_name"/> </submit> <submit> <label>Previous</label> <target formref="login_returning"/> </submit> </content> </form> <!-- ================================================= --> <!-- 2 - Trade name --> <!-- ================================================= --> <form id="f2_trade_name"> <title>Trade Name</title> <content> Trade name of business (if different from legal name entered above) <input fieldref="ss4.main.trade_name"> <prompt>Trade name, such as a DBA</prompt> </input> <submit> <label>Next</label> <target formref="f4a_mailing_address"/> </submit> <submit> <label>Previous</label> <target formref="f1_legal_name"/> </submit> </content> </form> <!-- ================================================= --> <!-- 4a - Address --> <!-- ================================================= --> <form id="f4a_mailing_address"> <title>Mailing Address</title> <content> Please enter your mailing address information below. <input fieldref="ss4.main.address1"> <prompt>Address number, street, and apt or suite #</prompt> </input> <input fieldref="ss4.main.address1_csz"> <prompt>City, state and zip</prompt> </input> <submit> <label>Next</label> <target formref="f5a"/> </submit> <submit> <label>Previous</label> <target formref="f2_trade_name"/> </submit> </content> </form> <!-- ================================================= --> <!-- 5a - Is address same --> <!-- ================================================= --> <form id="f5a"> <title>Street Address</title> <content> Is your street address the same as your mailing address <submit> <label>Yes</label> <target formref="f6_county"/> </submit> <submit> <label>No</label> <target formref="f5a_street_address"/> </submit> </content> </form> <!-- ================================================= --> <!-- 5a - Address --> <!-- ================================================= --> <form id="f5a_street_address"> <title>Street Address</title> <content> Please enter your business's physical street address information below. <input fieldref="ss4.main.address2"> <prompt>Address number, street, and apt or suite #</prompt> </input> <input fieldref="ss4.main.address2_csz"> <prompt>City, state and zip</prompt> </input> <submit> <label>Next</label> <target formref="f6_county"/> </submit> <submit> <label>Previous</label> <target formref="f5a"/> </submit> </content> </form> <!-- ================================================= --> <!-- 6 - county --> <!-- ================================================= --> <form id="f6_county"> <title>County and State</title> <content> What county is your business located in? <input fieldref="ss4.main.county"> <prompt>County</prompt> <mandatory/> </input> <submit> <label>Next</label> <target formref="f99_done"/> </submit> <submit> <label>Previous</label> <target formref="f5a"/> </submit> </content> </form> <!-- ================================================= --> <!-- 99 - done --> <!-- ================================================= --> <form id="f99_cancel"> <title>Operation Cancelled</title> <content> You have indicated you wish to exit the SS-4 system. Goodbye. </content> </form> <!-- ================================================= --> <!-- 99 - done --> <!-- ================================================= --> <form id="f99_done"> <title>All Finished</title> <content> Your SS-4 applicaiton is complete and will now be faxed to IRS. </content> </form> </form_genie>
#!/usr/bin/perl # Program .............. xml1 # Author ............... Ben Humphreys # Notice ............... Copyright (c) 2001-2002 BH Enterprises of NY, Inc. # Purpose .............. Prints all form elements # Comments ............. None use strict; use XML::Xerces; use XML::Xerces::DOMParse; my $command = shift || usage(); my $param = shift || usage(); { no strict 'refs'; &$command( $param ); } # ========================================================================= # Error handler # ========================================================================= sub error { my $error = shift; print STDERR "Error in eval: "; if (ref $error) { print STDERR "msg: ", $error->getMessage(); if (ref $error eq 'XML::Xerces::DOM_DOMException') { print STDERR "\n\tcode: ", $error->{code}; } print STDERR "\n"; } else { print STDERR $error; } } # ========================================================================= # Report our findings # ========================================================================= sub show_forms { my $file = shift || usage(); -f $file or die "File '$file' does not exist!\n"; my $parser = XML::Xerces::DOMParser->new(); $parser->parse ( XML::Xerces::LocalFileInputSource->new( $file ) ); my $document = $parser->getDocument (); my @form_nodes = $document->getElementsByTagName("form"); foreach my $form_node (@form_nodes) { print( $form_node->getNodeName() . "\n" ); my @child_nodes = $form_node->getChildNodes(); foreach my $child_node ( @child_nodes ) { print( " " . $child_node->getNodeName() . "\n" ); } } } # ========================================================================= # Create SQL structures based on a Form Genie ML file # ========================================================================= sub sql { my $file = shift || usage(); -f $file or die "File '$file' does not exist!\n"; my $parser = XML::Xerces::DOMParser->new(); eval{ $parser->parse ( XML::Xerces::LocalFileInputSource->new( $file ) ) }; my $document = $parser->getDocument (); my @field_nodes = $document->getElementsByTagName("field"); foreach my $field_node ( @field_nodes ) { print( "Element " . $field_node->getNodeName() . "\n" ); # Get field node attributes my %field_attributes = $field_node->getAttributes(); foreach my $key ( keys( %field_attributes ) ) { print(" Attr $key = " . $field_attributes{$key} . "\n" ); } # Get field node children my @child_nodes = $field_node->getChildNodes(); foreach my $child_node ( @child_nodes ) { print( " Value " . $child_node->getNodeName() . " = " . $child_node->getNodeValue() . "\n" ); } } } # ========================================================================= # Call external validator # ========================================================================= sub validate { my $file = shift; system("/usr/local/xml/xerces/bin/DOMPrint $file"); } # ========================================================================= # Unused code fragments # ========================================================================= sub unused { =pod $parser->setDoNamespaces ( 0 ); $parser->setCreateEntityReferenceNodes( 1 ); $parser->setDoSchema ( 0 ); $parser->setValidationScheme ( $XML::Xerces::DOMParser::Val_Always ); $parser->setErrorHandler ( XML::Xerces::PerlErrorHandler->new() ); =cut } # ========================================================================= # Print usage and exit # ========================================================================= sub usage { print("Usage: $0 [show_forms <fgml>] [validate <fgml>]\n"); print("Where: <fgml> is a Form Genie Markup Language File-form_genie.dtd\n"); print(" create_sql create SQL data structures from a Form Genie file\n"); print(" show_forms display all form elements within file\n"); print(" validate validate XML file against its DTD\n"); exit(0); }