Difference between revisions of "API:EPrints/XML"

From EPrints Documentation
Jump to: navigation, search
Line 1: Line 1:
urk
+
<!-- Pod2Wiki=_preamble_
 +
This page has been automatically generated from the EPrints 3.2 source. Any wiki changes made between the 'Pod2Wiki=*' and 'Edit below this comment' comments will be lost.
 +
-->
 +
__NOTOC__
 +
{{Pod2Wiki}}{{API:Source|file=EPrints/XML.pm|package_name=EPrints::XML}}[[Category:API|XML]]<div><!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=head_name --></div>
 +
==NAME==
 +
'''EPrints::XML''' - XML Abstraction Module
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=head_synopsis --></div>
 +
==SYNOPSIS==
 +
$string = EPrints::XML::to_string( $node, "utf-8", 1 ); #use this to convert DOM trees to string
 +
 
 +
$dom = EPrints::XML::parse_xml_string( $string );
 +
 
 +
$dom = EPrints::XML::parse_xml( $file, $basepath, $no_expand );
 +
 
 +
$boolean = is_dom( $node, @nodestrings );
 +
 
 +
$newnode = EPrints::XML::clone_node( $node, $deep );
 +
 
 +
EPrints::XML::write_xhtml_file( $node, $filename );
 +
 
 +
$document = EPrints::XML::make_document();
 +
 
 +
$dom = EPrints:XML::parse_url($url, $no_expand);
 +
 
 +
 
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=head_description --></div>
 +
==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.
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=item_parse_xml_string --></div>
 +
===$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.
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=item_parse_xml --></div>
 +
===$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.
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=item_event_parse --></div>
 +
===event_parse( $fh, $handler )===
 +
 
 +
Parses the XML from filehandle $fh, calling the appropriate events in the handler where necessary.
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=item_is_dom --></div>
 +
===$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.
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=item_dispose --></div>
 +
===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.
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=item_clone_node --></div>
 +
===$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 &amp; XML::GDOME but the result should be the same.
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=item_clone_and_own --></div>
 +
===$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.
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=item_to_string --></div>
 +
===$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. &lt;br/&gt; vs &lt;br /&gt;
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=item_make_document --></div>
 +
===$document = EPrints::XML::make_document()===
 +
 
 +
Create and return an empty document.
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=item_write_xml_file --></div>
 +
===EPrints::XML::write_xml_file( $node, $filename )===
 +
 
 +
Write the given XML node $node to file $filename.
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=item_write_xhtml_file --></div>
 +
===EPrints::XML::write_xhtml_file( $node, $filename )===
 +
 
 +
Write the given XML node $node to file $filename with an XHTML doctype.
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=item_tidy --></div>
 +
===EPrints::XML::tidy( $domtree, { collapse=&gt;['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.
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=item_namespace --></div>
 +
===$namespace = EPrints::XML::namespace( $thing, $version )===
 +
 
 +
Return the namespace for the given version of the eprints xml.
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=item_version --></div>
 +
===$v = EPrints::XML::version()===
 +
 
 +
Returns a string description of the current XML library and version.
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=item_parse_url --></div>
 +
===$dom = EPrints:XML::parse_url($url, $no_expand)===
 +
 
 +
Return a DOM document found at the URL
 +
 
 +
$url - the url which resolves to the XML you wish to parse.
 +
 
 +
$no_expand - set to 1 if you do not want the xml to be indented.
 +
 
 +
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<h4><span style='display:none'>User Comments</span></h4>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki=_postamble_ --><!-- Edit below this comment -->

Revision as of 15:54, 19 August 2009


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


NAME

EPrints::XML - XML Abstraction Module

User Comments


SYNOPSIS

$string = EPrints::XML::to_string( $node, "utf-8", 1 ); #use this to convert DOM trees to string

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

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

$boolean = is_dom( $node, @nodestrings );

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

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

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

$dom = EPrints:XML::parse_url($url, $no_expand);


User Comments


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.

User Comments


$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.

User Comments


$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.

User Comments


event_parse( $fh, $handler )

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

User Comments


$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.
 

User Comments


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.

User Comments


$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.

User Comments


$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.

User Comments


$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 />

User Comments


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

Create and return an empty document.

User Comments


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

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

User Comments


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

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

User Comments


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.

User Comments


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

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

User Comments


$v = EPrints::XML::version()

Returns a string description of the current XML library and version.

User Comments


$dom = EPrints:XML::parse_url($url, $no_expand)

Return a DOM document found at the URL

$url - the url which resolves to the XML you wish to parse.

$no_expand - set to 1 if you do not want the xml to be indented.

User Comments