Solved

Perl XML Problem(DOM)

Posted on 2004-08-21
2
298 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
Comment Utility
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 500 total points
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now