Solved

Perl XML Problem(DOM)

Posted on 2004-08-21
2
301 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 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl Frameworks 1 90
Perl Write to Specific line in a file 15 93
Adding a hidden div to each row in a table 6 71
.php tree directory? 5 72
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

772 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