Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Perl XML Problem(DOM)

Posted on 2004-08-21
2
Medium Priority
?
306 Views
Last Modified: 2013-11-19
Hello EvreyOne..I am trying to learn XML parsing with Perl.(I am using DOM)...I have stumbled upon a problem right away ..please help me with this.I get teh error
*******************************************************************
no element found at line 37, column 0, byte 1159 at /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi/XML/Parser.pm line 185
*******************************************************************

IN OTHER WORDS IF I WANT TO ACCESS THE INDIVIDUAL ELEMENTS IN A XML FILE THAT IS BASED ON A SCHEMA IS DOM THE OPTION ..IF SO WHY CANT I ACCESS THE FILE THAT IS BELOW

This is the XML file I am trying to parse and I thought I would use the DOM (I am not sure if I can do it though)
*******************************************************************
<?xml version="1.0" encoding="UTF-8" ?>
<model type="output" version="1.0"
       xmlns:xsi="http://www.w3.org/2001/SMLSchema-instance"
       xmlns="http://www.cs.uky.edu/wtw"
      xsi:schemaLocation="schema.xsd">

      <attribute name="Time of Day">
        <value name="Morning" utility="0"/>
        <value name="Evening" utility="0"/>
      </attribute>
      

      <attribute name="Course Load">
        <value name="12-14 Hours" utility="5"/>
        <value name="Fewer than 12 Hours" utility="4"/>
      </attribute>
      

      <attribute name="Professor">
        <value name="Goldsmith" utility="0"/>
            <dependency attribute="FreeTime" value="10 Hours or Fewer Free Time">
              <dependency attribute="Subject" value="Theory">
                  <value name="Klapper" utility="0"/>
              </dependency>
              <dependency attribute="Subject" value="Software Engineering">
                  <value name="Klapper" utility="2"/>
              </dependency>
            </dependency>
            <dependency attribute="FreeTime" value="20-25 Hours of Free Time">
              <dependency attribute="Time of Day" value="Afternoon">
                  <value name="Klapper" utility="1"/>
              </dependency>
            </dependency>
        <value name="Dekhtyar" utility="0"/>
        <value name="Baxter" utility="5"/>
      </attribute>
*******************************************************************

I am trying to access it with a simple script but it seems that I am unable to load the XML fget the parsing

*******************************************************************
use XML::DOM;

process_file( shift @ARGV );

sub process_file {
    my $infile = shift;
    my $dom_parser = new XML::DOM::Parser;            # create a parser object
    my $doc = $dom_parser->parsefile( $infile );      # make it parse a file
   
#    get_data($doc);
#      print $doc->toString;                             # output the tree again
       $doc->dispose;                                    # clean up memory
}
sub get_data {

      my $doc = shift;                                  
my $paras = $doc->getElementsByTagName( "attribute" );
    for( my $i = 0; $i < $paras->getLength; $i++ ) {
        my $para = $paras->item( $i );
        print "This is $para ";          
      }
}
******************************************************************
I am completely a novice (Bioinformatist) trying to get the rudiments of prog.. on weekends

Thanks so much for u'r time
0
Comment
Question by:micro_learner
2 Comments
 

Author Comment

by:micro_learner
ID: 11862163
Also please direct me for such kind of case which one is the best option ..DOM ,SAX or anything simpler.What I basically want to do is get the attributes and values and just do some manupilations and print then out in a text file..or something on that lines.

Any tutorial or example code would be really helpful.Thanks so much
0
 
LVL 10

Accepted Solution

by:
rj2 earned 2000 total points
ID: 11863252
The xml file needs a closing </model> tag to be well-formed.
Does the error disappear if you add </model> to the end of the xml file?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question