API:EPrints/XML

From EPrints Documentation
Revision as of 18:29, 11 August 2009 by Tdb01r (talk | contribs) (New page: <!-- Pod2Wiki=_preamble_ This page has been automatically generated from the EPrints source. Any wiki changes made between the 'Pod2Wiki=*' and 'End of Pod2Wiki' comments will be lost. -...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Latest Source Code (3.4, 3.3) | Revision Log | Before editing this page please read Pod2Wiki

NAME

EPrints::XML - XML Abstraction Module

DESCRIPTION

EPrints can use either XML::DOM, XML::LibXML or XML::GDOME modules to generate and process XML. Some of the functionality of these modules differs so this module abstracts such functionality so that all the module specific code is in one place.

parse_xml_string

 $doc = EPrints::XML::parse_xml_string( $string );

Return a DOM document describing the XML string %string.

If we are using GDOME then it will create an XML::GDOME document instead.

In the event of an error in the XML file, report to STDERR and return undef.

parse_xml

 $doc = EPrints::XML::parse_xml( $file, $basepath, $no_expand )

Return a DOM document describing the XML file specified by $file. With the optional root path for looking for the DTD of $basepath. If $noexpand is true then entities will not be expanded.

If we are using GDOME then it will create an XML::GDOME document instead.

In the event of an error in the XML file, report to STDERR and return undef.

event_parse

 event_parse( $fh, $handler )

Parses the XML from filehandle $fh, calling the appropriate events in the handler where necessary.

is_dom

 $boolean = is_dom( $node, @nodestrings )
return true if node is an object of type XML::DOM/GDOME::$nodestring
where $nodestring is any value in @nodestrings.
 
if $nodestring is not defined then return true if $node is any 
XML::DOM/GDOME object.
 

dispose

 EPrints::XML::dispose( $node )

Dispose of this node if needed. Only XML::DOM nodes need to be disposed as they have cyclic references. XML::GDOME nodes are C structs.

clone_node

 $newnode = EPrints::XML::clone_node( $node, $deep )

Clone the given DOM node and return the new node. Always does a deep copy.

This function does different things for XML::DOM & XML::GDOME but the result should be the same.

clone_and_own

 $newnode = EPrints::XML::clone_and_own( $doc, $node, $deep )

This function abstracts the different ways that XML::DOM and XML::GDOME allow objects to be moved between documents.

It returns a clone of $node but belonging to the document $doc no matter what document $node belongs to.

If $deep is true then the clone will also clone all nodes belonging to $node, recursively.

to_string

 $string = EPrints::XML::to_string( $node, [$enc], [$noxmlns] )

Return the given node (and its children) as a UTF8 encoded string.

$enc is only used when $node is a document.

If $stripxmlns is true then all xmlns attributes and namespace prefixes are removed. Handy for making legal XHTML.

Papers over some cracks, specifically that XML::GDOME does not support toString on a DocumentFragment, and that XML::GDOME does not insert a space before the / in tags with no children, which confuses some browsers. Eg. <br/> vs <br />

make_document

 $document = EPrints::XML::make_document()

Create and return an empty document.

write_xml_file

 EPrints::XML::write_xml_file( $node, $filename )

Write the given XML node $node to file $filename.

write_xhtml_file

 EPrints::XML::write_xhtml_file( $node, $filename )

Write the given XML node $node to file $filename with an XHTML doctype.

tidy

 EPrints::XML::tidy( $domtree, { collapse=>['element','element'...] }, [$indent] )

Neatly indent the DOM tree.

Note that this should not be done to XHTML as the differenct between white space and no white space does matter sometimes.

This method modifies the tree it is given. Possibly there should be a version which returns a new version without modifying the tree.

Indent is the number of levels to ident by.

namespace

 $namespace = EPrints::XML::namespace( $thing, $version )

Return the namespace for the given version of the eprints xml.

UNDOCUMENTED METHODS

Warning These methods were found in the source code but didn't have any POD associated with them. This may be because we haven't got around to documenting them yet or it could be because they are internal to the API and not intended for use by other parts of EPrints.

contents_of

debug_xml

document_to_string

is_empty

make_document_fragment

parse_url

trim_whitespace