Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Perl XML Problem(DOM)

Posted on 2004-08-21
2
Medium Priority
?
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Six Sigma Control Plans

721 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