Re: How to: Basic XML Parsing with Perl
[email protected] (Jason E. Stewart)
| Newsgroups | gmane.text.xml.xerces-p.devel |
|---|---|
| Message-ID | <[email protected]> |
"Stephen Christensen" <[email protected]> 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.