InstantXML - Temporary Perl Module for DOM Level 1
Alternative
You'd better try the XML::DOM module first.
Feature
- This is a Perl module to
manipulate data written in XML.
- If you have not heard about XML or DOM, this may not be what you looking
for.
- This provides a subset of DOM (Core)
Level 1 (Version 1.0) interface.
- This also provides a very simple parser.
- All written in Perl for the sake of platform portability.
- This module is provided for temporary use until "Perl will soon support API for XML" come true.
- The module of parser is separated from modules of DOM classes. So you can
write your own parser.
- You can use this module with no charge for any purpose, but without warranty.
- You can redistribute Ver.0.41 and the later as it is, for any purpose.
- If you make altered version of this software, you should make it clear so
that other people can distingish it from the original set.
- You have to use or redistribute this software on your own responsibility.
- Do appropriate tests enough for your use. And I do not recommend this for
critical uses.
- Earily versions were called 'TmpL1'.
- InstantXML contains cyclic-reference between a parent node and its child
node. This means that the garbage on memory retains till perl exit.
- Nothing concerned about 'exceptions'. Ileagal use of DOM methods or any
errors in XML syntax are not assumed.
- Nothing concerned about character sets. Simply, all visible sequences in
XML are stored in Perl's scalar variable.
- There are many unsupported methods. Those may call Carp::croak().
See here.
- I am really sorry not to provide enough documents about this module.
Download (via http)
InstantXML
Ver.0.55 (latest snapshot)
SP1for053.pm (Supplement)
InstantXML
Ver.0.53 (stable, Oct 21 1988)
InstantXML
Ver.0.51 (beta, Oct 1988)
How to use KParser
KParser is an sample supplement. But it provides the most easy way to use this
package. See the file t/sample.t and t/tester.t as an example.
Put the folder(or directory) 'InstantXML' into your library path (@INC). Put
the following declaration at the begining of your script.
use InstantXML::KParser;
The following expression returns a object with the Interface 'DocumentFragment'.
InstantXML::KParser->parseFragment($string_with_xml_tags)
or simply, parseFragment($string_with_xml_tags)
In current version of KParser, note that the firstChild of a fragment will be a
Text node even if it is of space only.
The following expression returns string with tags, where $your_node is a Node
object.
InstantXML::KParser->unparseNode($your_node) or
simply, unparseNode($your_node)
How to get access to the DOM objects
DOM Level 1 attributes can be accessed by Perl methods which has the same name
preceeded by prefix 'get_' or 'set_'.
$your_node->get_nodeName;
$your_node->set_nodeValue("This is a new value.");
DOM Level 1's methods can be called by Perl methods of the same name. Note that
many of methods are not implemented.
$your_node->childNodes();
DOM Level 1's null is expressed as Perl "undef" value. So you may need
to test some returned values by "defined".
DOM Level 1's wstring is expressed as Perl scalar.
A DOM Level 1's NodeList can be manipulated as a reference of Perl array. But
remember that those are out of DOM Level 1. And a NamedNodeMap, a reference of
Perl hash.
In case you need some better DOM class implementation(for exaple, Element), I
suggest your Element class inherits your Node class (if exists) AND my
TmpElement class. You may do this, when you need implementation of exception, or
need to correct my bugs on method immediately, etc.
How to create a node
Kit.pm provides a subroutine create_Document_DOMLevel1 , which
returns a new Document object. Other objects can be created by methods of
Document object.
For more detail, please hack 'Kit.pm'. It's not comlicated.
And KParser.pm is a dirty example for it.
Known problems
- Return value of NamedNodeMap->setNamedItem is not available. (-Ver.053)
- Inserting DocumentFragment as children does not work correctly.
- KParser is not concerned about things such as
".(-Ver.051)
- Hated by Perl of some earlier versions (maybe 5.003) (-Ver.050)
- Uncompleted getElementsByTagName was exposed (???-Ver.0.44)
Memos
- My testing enviromnet was ActivePerl502 on WindowsNT.
Sponsors
-
BrickYard Graphics - Free graphics for your web site - icons, buttons, backgrounds, textures, rules, banner blanks, animations and more!
-
Krislyn's Webmaster Resources - Sources of information on HTML, XML, fonts, icons, graphics, chat, affiliate programs, domain
registration, PERL, CGI, and more. One of 50 subject areas at Krislyn's Strictly Business Sites.
-
Adgrafix - One stop web site hosting! - Adgrafix Web Hosting - NO setup fees! - E-commerce ready! - Unlimited Email accounts - Loads of preinstalled scripts! - 30 day free trial! - PLUS sign up as a reseller and get a FREE web site with only 3 sales. What are you waiting for?
Latest version of this document may be found at http://kojun.webalias.com/InstantXML/