|
Page 2 of 2
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
Trackback(0)

|