Solved

Perl XML Problem(DOM)

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

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…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…
Suggested Courses

624 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