I am trying to pull some simple contact information out of a XML file:
<Project> <Contacts> <Contact type="Application"> <Name>Shawn Penn</Name> <WorkPhone>111-111-1111</WorkPhone> <Pager>999-999-9999</Pager> <Scope>Manager</Scope> </Contact> <Contact type="Application"> <Name>George Lucos</Name> <WorkPhone>111-111-1111</WorkPhone> <Pager>999-999-9999</Pager> <Scope>Manager</Scope> </Contact> </Contacts> </Project>
My perl program is as follows:
#!/usr/bin/perl -w use CGI qw(:standard :html :forms); use strict; use XML::XPath; use XML::XPath::XMLParser; use XML::DOM; #------------------------------- # Declare variables my $WebPage = CGI::new(); ### Create web page output des +tination ### Pull in application name of file to read from my $SourceXMLDir = "/doc/staging/ProjectInfo/" . $WebPage->param(App) +. ".xml"; ### Open XML file my $XMLFile = XML::XPath->new( filename => $SourceXMLDir ); my $ParseFile = new XML::DOM::Parser; my $XMLDOMFile = $ParseFile->parsefile ($SourceXMLDir ); #---------------END File Declaration----- ### header print $WebPage->header, $WebPage->start_html("Project Information for $ProjectName"); print "\n"; print $WebPage->h1("Contact Information for $ProjectName"), $WebPage->hr, "<table BORDER COLS=2 WIDTH=100% NOSAVE>\n", "<tr><th>Primary</th><th>Secondary</th></tr>\n", "<tr><td>", $XMLFile->find( "/Project/Contacts/Contact[\@type='Primary']/N +ame/text()" ), "</td><td>", $XMLFile->find( "/Project/Contacts/Contact[\@type='Secondary'] +/Name/text()" ), "&nbsp</td></tr>\n", "</table>\n"; my $AppNode = $XMLDOMFile->getElementsByTagName ("Contact"); my $numberNodes = $AppNode->getLength; print "<table BORDER COLS=4 WIDTH=100% >\n", "<tr><th>Scope</th><th>Name</th><th>Work Phone</th><th>Pager</ +th></tr>\n", "<tr>\n"; for (my $loopIndex = 0; $loopIndex < $numberNodes; $loopIndex++) { "<td>", my $ScopeText = $AppNode->item($loopIndex)->getFirstChild()->g +etNodeValue(); } "</td>\n</tr>", "</table>\n"; print "\n"; print $WebPage->end_html; print "\n";
The perl script runs but it does not pull in any data with the getElementsByTagName() call. It Doesn't even run the for loop. Any ideas?

In reply to XML::DOM::Parser not getting data by Anonymous Monk

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.