Any interest in Perl and XML

Bob La Quey robertl1 at home.com
Fri May 19 17:23:35 CDT 2000


~sdpm~
In the previous post I supplied code for a simple parser 
written in using XML::Parser. Now let's run it on the file 
test.xml defined as:

<message> 
	<p> Hello World 
	    	<s> Why not?</s> xxx
   zzzz	<s> Keep on trying.</s> yyyyy 
	</p>
</message>


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Invoke the XML::Parser with simple handlers for 
Init, Start, End, Final (i.e. leave out the Char handler)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
%./xmltool0.pl test.xml 

Starting XML parsing
    <message>
        <p>
            <s>
            </s>
            <s>
            </s>
        </p>
    </message>
End of XML parsing
%
%

Now suppose there is an error in the XML 
e.g a mismatched tag 

test1.xml 
<message> 
	<p> Hello World 
	    <s> Why not?</s> 
   	    <s> Keep on trying.</s> 
   	    <s> huh 
	</p> 
</message>

The parser produces 

Starting XML parsing
    <message>
        <p>
            <s>
            </s>
            <s>
            </s>
            <s>
   	    <s> huh 
	</p> 
==^ mismatched tag at line 7, column 3, byte 106:
</message>


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Now Add the handler for Char 
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
%./xmltool.pl test.xml

Starting XML parsing
    <message>
    char_handler, current tag <message> data element = " "
    char_handler, current tag <message> data element = "
"
    char_handler, current tag <message> data element = "	"
        <p>
        char_handler, current tag <p> data element = " Hello World "
        char_handler, current tag <p> data element = "
"
        char_handler, current tag <p> data element = "	    "
            <s>
            char_handler, current tag <s> data element = " Why not?"
            </s>
        char_handler, current tag <p> data element = " xxx"
        char_handler, current tag <p> data element = "
"
        char_handler, current tag <p> data element = "   zzzz	    "
            <s>
            char_handler, current tag <s> data element = " Keep on trying."
            </s>
        char_handler, current tag <p> data element = " yyyyy "
        char_handler, current tag <p> data element = "
"
        char_handler, current tag <p> data element = "	"
        </p>
    char_handler, current tag <message> data element = "
"
    </message>
End of XML parsing
%

The Char event is called each time a string which is not a tag 
is recognized. Note strings are terminated (or started) by 
either tags or line feeds. A line feed generates a Char event. 

Ok, that will do till we get some feed back. Then I wiil
provide some motivation for using XML (or others can jump in) 
and show some more useful examples of things you can do.

Come folks let's get it on. 



~sdpm~

The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.




More information about the San-Diego-pm mailing list