You are viewing a plain text version of this content. The canonical link for it is here.
Posted to p-dev@xerces.apache.org by Stephen Christensen <sm...@hotmail.com> on 2003/09/10 21:50:29 UTC
How to: Basic XML Parsing with Perl
Hi. I'm a high school student working at the University of Kentucky after
school most days on a research project. I'm working with the Computer
Science department, and my mentor has assigned me a project that involves
parsing XML.
Before I started on this research project, I had taken two semesters of C++,
and that's all. Now, I have made a couple of dozen programs with Perl,
several decent CGI applications, and messed around with Javascript and HTML.
To finish the research project, I need to be able to parse XML, preferably
with Perl. Specifically, I need to be able to take an XML document, parse
it, and make each node available for a user to edit.
My problem is this: I have no idea (programming-wise) what to do after
eval {$parser->parse ($file)};
I need to have a loop that analyzes each node of the document and seperates
it into sections based on the nodenames. However... I have no idea how to
do this. None of the samples on the Perl site seemed to help. Likewise,
there is no API, except a reference to the C++ API. I don't have enough
experience with either programming language to be able to figure out how to
parse with Perl. I've been banging my head against the wall the past month
trying to figure it out.
Finally, to my question. Can someone either give me a sample Perl file that
uses Xerces, or perhaps walk me through how to use it?
I apologize for how basic this question is... I'm ashamed to clutter the
developer mailing list with it. But really, I'm having great difficulty
finding any documentation for Xerces Perl.
Thanks a million for any help you can give,
~Stephen Christensen
Senior, Dunbar High School
_________________________________________________________________
Fast, faster, fastest: Upgrade to Cable or DSL today!
https://broadband.msn.com
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org
Re: How to: Basic XML Parsing with Perl
Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Stephen Christensen" <sm...@hotmail.com> writes:
> I apologize for how basic this question is... I'm ashamed to clutter
> the developer mailing list with it. But really, I'm having great
> difficulty finding any documentation for Xerces Perl.
'sno trouble 'tall.
Actually this list serves double duty as the dev list and the user
list - kind of silly I suppose, but the traffic isn't high enough to
warrant another list.
And yes, lack of Perl documentation is a pain. I'd still love to have
a volunteer write some good Perl docs.
> My problem is this: I have no idea (programming-wise) what to do after
> eval {$parser->parse ($file)};
>
> I need to have a loop that analyzes each node of the document and
> seperates it into sections based on the nodenames.
You can either use the SAX API which will stop at every Element during
parsing, or you can use the DOM API which will give you an in memory
data structure that you can traverse after parsing is complete.
Perhaps in your case DOM is better, since you want to allow the user
to modify the document, that way you can simply write out the modified
DOM Document when you're finished editing.
In this case, I'd have a look at DOMNodeIterator or DOMTreeWalker
classes (I think DOMNodeIterator is now the standard way). There are
some simple examples in the test directory for both:
t/DOMNodeIterator.t
t/DOMTreeWalker.t
That will give you a starting point
> I've been banging my head against the wall the past month trying to
> figure it out.
Ouch, sorry you've been at it that long. Next time, feel free to write
immediately, and we'll try to help as much as we can.
Cheers,
jas.
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org