Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

Working with XML in Perl

By Exforsys | on September 6, 2007 |
XML Tutorial

Working with XML in Perl

Extensive Markup language or the XML is a sort of data storage; it is very structured and mapped out. There are two most important aspects of XML that has to be covered, one is writing in XML and reading it out in XML. Parsers have already been created in XML and knowing how these parsers can be used is very important to program using XML and Perl as a combination. These parsers prepare the data so that it can worked on immediately, they in a way make it ready to use or to be programmed with. If the data is ready then it is like half the job is done. Parsers have various options inbuilt in them which allow you to design your own output.

Parsers in XML

A file expression filter runs a file line by line and reading one single character at a time and this process is called the file input and output process in programming and is considered to be a crucial step towards file process. Raw text usually is very unclear, disarrayed and disorganized. XML has evolved due to this need for structured data in file processing because it provides rules, creates boundaries and overall is a very predictable program.

The job of a XML parser is to translate XML data which is achieved by using XML libraries. The data is translated into a data object or events and therefore enabling your program to have access to structured data. Basically parsers bridge the gap between the XML data and the language that your program might have been using before XML.

A parser would however accept only well formed XML documents and rejects whichever has errors in formation. Its functionalities are mainly, reading the data and differentiating between markup and data, replacing the entities with known values, collecting documents based on their logic even from disparate sources and compiling them at one place, reporting syntax and grammatical errors or validation errors, and finally serving data in a structured format to the program.

Usually in Extensive markup language the data and the markup are all jumbled up together, so the parser basically has to tell the difference between the two and separate them as well by sifting through the characters. Few characters like the ampersand, semi colon, and some special characters delimit the instructions from the actual data.

The parser should also be able to tell when to receive a certain instruction and if it is a good instruction or a bad instruction like for example the elements need to have a bracket at the start of a tag and also need a bracket t the end of a tag. Using this parser can easily identify the character stream and slot them into separate sections based on the XML instructions.

Usually there will be some entities or entity references that need to be resolved in a XML document. In the beginning of parsing the parser usually encounters a list of entity declarations which associate an identifier with every entity. Because these entities will have references to entities within themselves it becomes extensive for the parser to separate and parse them. But it is not essential that all entities have to be parsed or resolved. This typically happens in cases where you are spitting the XML back after a minor processing session.

Sometimes you may just have the need to resolve the external entities and not the internal ones. Many parsers will however permit you to do this with an exception that the parser will not let you use an entity which has not been declared.

Going further if you let your parser resolve the entities it is going to fetch all the documents internal and external of the larger XML document. Due to this while interpretation it is likely that the parser will come across a syntax error because the XML is designed to do this. So when a parser does come across such errors it just shuts down the application.

Perl Parser

Usually it is a very time consuming process to write a parser. You have to make sure everything has been covered and this takes a lot of testing. Tools like Perl XML parser turn out to be useful in these circumstances. Perl programmers can find ready to use Perl modules to work on their programs on the Comprehensive Perl Archive Network or the CPAN. It is a mirrored site for public purpose and all its resources are free. You will find a plentitude of ready made modules for Perl and XML.

However it is not to be misunderstood for a library which provides ready made modules for Perl and XML programming. It has to be used like a toolkit which will help you build a solution for your program. XML parsers differ from each other in 2 ways which are major. They are different with their parsing style itself like in cases when they create a data structure or an event stream. XML Perl based parser is a multifaceted parser which has a few parsing styles to offer.

XML Perl parser parses the document at a reasonable amount of speed and also with flexibility.

Parsing styles in XML and Perl

XML Perl Parser offers many different ways to parse a XML document but these parsing styles however do not change the way and XML document is read, it only changes the way it is presented forth.

Debug: Debug prints the documents to STDOUT and formats the outline of the document and it does not return any special or specific values to the program.

Tree: The tree creates a tree shaped data structure which is hierarchical and can be easily processed by the document. They consist of nested hashes and arrays.

Objects: Similar to the tree this method holds a reference to the hierarchical structure which represents the document. Instead of using nested hashes and arrays it uses objects

Subs: Subs offer a way to set up callback functions to handle individual elements. You can use the pkg function to create a package of elements and ask the parser to use the pkg function in Perl XML. So when a parser finds an element in the start tag it will look for that element name in the pkg function.

Streams: Similar to the subs the streams will define the call backs to be able to handle certain XML components which are general in nature. You can write functions which can be named handlers that will call for events and processing instructions. However this handler option has to be registered.

Differences in stream and tree based parsing procedures in Perl XML

There is always more than one way to do anything. XML offers many options to work on a document based on the preferences and resources that programmer have. You may need a parser which requires low maintenance or a parser that has to give more performance output. Depending on these kinds of needs you can design your XML Perl Parser.

Between the Trees based parsing and the stream based parsing the parsers will have different role to play. In the stream based parsing style the parser constantly send s alerts to the program for any change in patterns in the XML document. It is like flushing down everything from a pipe, it takes all the parsing elements, parses them from one end and flushes them out into the program on another end creating a continuous flow of data. This phenomenon can be named the event stream.

Whereas in the tree based strategy the parser retains all the information to itself until the end when it completes creating a structure for the data and presents it in wholesome manner to the program. The data is going to be well structured by the time it gets presented to the program in the tree parsing system of the XML Perl. This model proves to be helpful with XML data which is raw. The XML Perl tree based strategy functions somewhat like a camera which takes a picture and presents you a copy. Similarly the data is replicated by the tree based strategy and presented.

Well which one to use is question that you have to answer yourself based on the fact that which one will be more beneficial for you strategically. Both have their advantages and disadvantages. For example event streams in the stream based strategy are faster and use much lesser memory and are more pipelined and organized. But they are also extensive in coding and store the data temporary. Tree based strategy lets you keep the data till the end and also is simple in coding. It also uses less processor time and less memory.

The tree base strategy and the stream based strategy are intertwined in a way and they share a relationship within their internal qualities. Because the stream based strategy builds the structure for the tree based strategy and this you will realize only when you take a closer look at their attributes. However both have proved efficient way for parsing in the extensive markup language and Perl parsing scenario.

Online Resource
Perl and XML
AxKit – An XML Delivery Toolkit for Apache
XML CGI
XML Parser
XML OCS

« « Can RFID Help Your Supply Chain?
Working with XML in C » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 0 Followers
  • Popular
  • Recent
  • XML Processing

    July 16, 2007 - 0 Comment
  • XML – Elements, Attributes, Entities

    May 14, 2006 - 0 Comment
  • XML Remote Calling Procedure

    July 19, 2007 - 0 Comment
  • XML – Document Type Definitions (DTD)

    June 14, 2006 - 0 Comment
  • XML Security

    July 21, 2007 - 0 Comment
  • XML – Elements in Document Type Definitions (DTD)

    June 14, 2006 - 0 Comment
  • XML SQL Server

    July 23, 2007 - 0 Comment
  • Working with XML in Flash

    August 30, 2007 - 0 Comment
  • XML and Service Oriented Architecture

    July 25, 2007 - 0 Comment
  • Working with XML in Python

    September 2, 2007 - 0 Comment
  • Working with XML in C

    September 7, 2007 - 0 Comment
  • Working with XML in Python

    September 2, 2007 - 0 Comment
  • Working with XML in Flash

    August 30, 2007 - 0 Comment
  • Working with XML in Oracle

    August 30, 2007 - 0 Comment
  • Working with XML in Visual Basic

    August 28, 2007 - 0 Comment
  • Using XML with Microsoft Excel

    August 24, 2007 - 0 Comment
  • XML Spy

    August 24, 2007 - 0 Comment
  • XML and Service Oriented Architecture

    July 25, 2007 - 0 Comment
  • XML SQL Server

    July 23, 2007 - 0 Comment
  • XML Security

    July 21, 2007 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • Working with XML in C
  • Working with XML in Python
  • Working with XML in Flash
  • Working with XML in Oracle
  • Working with XML in Visual Basic

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT