XML::Toolkit Tools to Ease the Pain
Chris Prather
HD Publishing Group
Who Am I?
- Perl Developer
- Moose Developer
- Closet XML Lover
The Backstory
- Customer had an Flash site
- Flash was controlled by XML
- “Build us a CMS for our XML!”
The Backstory (cont.)
- Aha! I can whip out my XML Knowledge!
- This was naughty, I didn’t check CPAN
XML::Compile
XML::Pastor
- Not all bad
- my wheel is round in a different way
- I’ll get to this later
The Backstory (cont.)
- Me: Send me the DTD or Schema, this is cake!
- Them: … what’s a DTD?
- Me: Well send me your XML, if it’s well formed I can deal with that too
- Them: … Well formed?
- Me: … [redacted]
The Backstory (cont.)
- After much hassleling between Stevan and them
- XML::Toolkit was born
The Requirements
- Had to Round Trip existing documents
- Elements in the same order because they weren’t using XPath
- Had to infer the schema from existing documents
- Had to be able to generate new documents that fit the above
The Architecture
- SAX
- SAX ➢ Moose Class
- SAX ➢ Moose Object
- Moose ➢ XML (via SAX)
SAX ➢ Moose Class
xmltk generate --input [XML]
- Parse XML
- For every Element generate a class
- Attributes
- Children become a collection
SAX ➢ Moose Class
- Won’t work properly with mixed elements
- Doesn’t accurately reflect the real schema
- “Only One Child”
- One or Many
- Data Types
- Works pretty damn well for an 80%
SAX ➢ Moose Object
xmltk validate --input [XML]
- Parse XML
- For every Element create an object
- populate Attributes
- Push children into collections
Moose ➢ XML (via SAX)
xmltk validate --input [XML]
- Parse Moose Objects in memory
- For every object fire
start_element
- for every text attribute fire
characters
- Let
XML::SAX::Writer do the real work
What’s Next
- Finish Namespace Support
- DTD / RelaxNG support
- Performance enhancements
Class::XML rewrite
Colophon
- Titling: Goudy Bookletter @ 1911 48pt
- Body: Goudy Bookletter 1911 @ 24pt
- Code:
Inconsolata @ 24pt
- Presentation: Markdown + S5