Difference between revisions of "API:EPrints/XML"

From EPrints Documentation
Jump to: navigation, search
Line 20: Line 20:
 
<!-- Pod2Wiki=head_synopsis --></div>
 
<!-- Pod2Wiki=head_synopsis --></div>
 
==SYNOPSIS==
 
==SYNOPSIS==
   $string = EPrints::XML::to_string( $node, "utf-8", 1 ); #use this to convert DOM trees to string
+
   my $xml = $repository-&gt;xml;
 
    
 
    
   $dom = EPrints::XML::parse_xml_string( $string );
+
   $doc = $xml-&gt;parse_string( $string );
 +
  $doc = $xml-&gt;parse_file( $filename );
 +
  $doc = $xml-&gt;parse_url( $url );
 
    
 
    
   $dom = EPrints::XML::parse_xml( $file, $basepath, $no_expand );
+
   $utf8_string = $xml-&gt;to_string( $dom_node, %opts );
 
    
 
    
   $boolean = is_dom( $node, @nodestrings );
+
   $dom_node = $xml-&gt;clone( $dom_node ); # deep
 +
  $dom_node = $xml-&gt;clone_node( $dom_node ); # shallow
 
    
 
    
   $newnode = EPrints::XML::clone_node( $node, $deep );
+
  # clone and return child nodes
 +
   $dom_node = $xml-&gt;contents_of( $dom_node );
 +
  # Return text child nodes as a string
 +
  $utf8_string = $xml-&gt;text_contents_of( $dom_node );
 
    
 
    
   EPrints::XML::write_xhtml_file( $node, $filename );
+
   $dom_node = $xml-&gt;create_element( $name, %attr );
 +
  $dom_node = $xml-&gt;create_text_node( $value );
 +
  $dom_node = $xml-&gt;create_comment( $value );
 +
  $dom_node = $xml-&gt;create_document_fragment;
 
    
 
    
   $document = EPrints::XML::make_document();
+
   $xml-&gt;dispose( $dom_node );
 
    
 
    
  $dom = EPrints:XML::parse_url($url, $no_expand);
+
head1 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: #e8e8f; 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_methods --></div>
 +
==METHODS==
 +
<div style='background-color: #e8e8f; 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_parsing --></div>
 +
===Parsing===
 +
<div style='background-color: #e8e8f; 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_string --></div>
 +
====$doc = $xml-&gt;parse_string( $string, %opts )====
 +
 
 +
Returns an XML document parsed from $string.
 +
 
 +
<div style='background-color: #e8e8f; 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_file --></div>
 +
====$doc = $xml-&gt;parse_file( $filename, %opts )====
 +
 
 +
Returns an XML document parsed from the file called $filename.
 +
 
 +
  base_path - base path to load DTD files from
 +
  no_expand - don't expand entities
 
    
 
    
 +
<div style='background-color: #e8e8f; 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>
 +
====$doc = $xml-&gt;parse_url( $url, %opts )====
 +
 +
Returns an XML document parsed from the content located at $url.
 +
 +
<div style='background-color: #e8e8f; 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_node_creation --></div>
 +
===Node Creation===
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; 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>
 
<h4><span style='display:none'>User Comments</span></h4>
Line 43: Line 106:
  
  
<!-- Pod2Wiki=head_description --></div>
+
<!-- Pod2Wiki=item_create_element --></div>
==DESCRIPTION==
+
====$node = $xml-&gt;create_element( $name [, @attrs ] )====
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.  
+
 
 +
Returns a new XML element named $name with optional attribute pairs @attrs.
 +
 
 +
<div style='background-color: #e8e8f; 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_create_cdata_section --></div>
 +
====$node = $xml-&gt;create_cdata_section( $value )====
 +
 
 +
Returns a CDATA section containing $value.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 52: Line 126:
  
  
<!-- Pod2Wiki=item_parse_xml_string --></div>
+
<!-- Pod2Wiki=item_create_text_node --></div>
===$doc = EPrints::XML::parse_xml_string( $string );===
+
====$node = $xml-&gt;create_text_node( $value )====
 +
 
 +
Returns a new XML text node containing $value.
 +
 
 +
<div style='background-color: #e8e8f; 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 -->
  
Return a DOM document describing the XML string %string.
 
  
If we are using GDOME then it will create an XML::GDOME document instead.
+
<!-- Pod2Wiki=item_create_comment --></div>
 +
====$node = $xml-&gt;create_comment( $value )====
  
In the event of an error in the XML file, report to STDERR and return undef.
+
Returns a new XML comment containing $value.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 66: Line 146:
  
  
<!-- Pod2Wiki=item_parse_xml --></div>
+
<!-- Pod2Wiki=item_create_document_fragment --></div>
===$doc = EPrints::XML::parse_xml( $file, $basepath, $no_expand )===
+
====$node = $xml-&gt;create_document_fragment====
  
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.
+
Returns a new XML document fragment.
  
If we are using GDOME then it will create an XML::GDOME document instead.
+
<div style='background-color: #e8e8f; 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 -->
  
In the event of an error in the XML file, report to STDERR and return undef.
 
  
 +
<!-- Pod2Wiki=head_other --></div>
 +
===Other===
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; 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>
 
<h4><span style='display:none'>User Comments</span></h4>
Line 80: Line 163:
  
  
<!-- Pod2Wiki=item_event_parse --></div>
+
<!-- Pod2Wiki=item_is --></div>
===event_parse( $fh, $handler )===
+
====$bool = $xml-&gt;is( $node, $type [, $type ... ] )====
  
Parses the XML from filehandle $fh, calling the appropriate events in the handler where necessary.
+
Returns true if $node is one of the given node types: Document, DocumentFragment, Element, Comment, Text.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 90: Line 173:
  
  
<!-- Pod2Wiki=item_is_dom --></div>
+
<!-- Pod2Wiki=item_clone --></div>
===$boolean = is_dom( $node, @nodestrings )===
+
====$node = $xml-&gt;clone( $node )====
 +
 
 +
Returns a deep clone of $node. The new node(s) will be owned by this object.
  
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: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; 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>
 
<h4><span style='display:none'>User Comments</span></h4>
Line 104: Line 183:
  
  
<!-- Pod2Wiki=item_dispose --></div>
+
<!-- Pod2Wiki=item_clone_node --></div>
===EPrints::XML::dispose( $node )===
+
====$node = $xml-&gt;clone_node( $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.
+
Returns a clone of $node only (no children). The new node will be owned by this object.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 115: Line 194:
  
 
<!-- Pod2Wiki=item_clone_node --></div>
 
<!-- Pod2Wiki=item_clone_node --></div>
===$newnode = EPrints::XML::clone_node( $node, $deep )===
+
====$node = EPrints::XML::clone_node( $node [, $deep ] )====
  
Clone the given DOM node and return the new node. Always does a deep copy.
+
DEPRECATED.
  
This function does different things for XML::DOM &amp; XML::GDOME but the result should be the same.
+
<div style='background-color: #e8e8f; 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_contents_of --></div>
 +
====$node = $xml-&gt;contents_of( $node )====
 +
 
 +
Returns a document fragment containing a copy of all the children of $node.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 126: Line 213:
  
  
<!-- Pod2Wiki=item_clone_and_own --></div>
+
<!-- Pod2Wiki=item_text_contents_of --></div>
===$newnode = EPrints::XML::clone_and_own( $doc, $node, $deep )===
+
====$string = $xml-&gt;text_contents_of( $node )====
 +
 
 +
Returns the concantenated value of all text nodes in $node (or the value of $node if $node is a text node).
 +
 
 +
<div style='background-color: #e8e8f; 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>
 +
====$utf8_string = $xml-&gt;to_string( $node, %opts )====
  
This function abstracts the different ways that XML::DOM and  XML::GDOME allow objects to be moved between documents.  
+
Serialises and returns the $node as a UTF-8 string.
  
It returns a clone of $node but belonging to the document $doc no matter what document $node belongs to.  
+
To generate an XHTML string see [[API:EPrints/XHTML|EPrints::XHTML]].
  
If $deep is true then the clone will also clone all nodes belonging to $node, recursively.
+
Options:
 +
indent - if true will indent the XML tree
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 141: Line 239:
  
 
<!-- Pod2Wiki=item_to_string --></div>
 
<!-- Pod2Wiki=item_to_string --></div>
===$string = EPrints::XML::to_string( $node, [$enc], [$noxmlns] )===
+
====$string = EPrints::XML::to_string( $node, [$enc], [$noxmlns] )====
  
 
Return the given node (and its children) as a UTF8 encoded string.
 
Return the given node (and its children) as a UTF8 encoded string.
Line 150: Line 248:
  
 
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;
 
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: #e8e8f; 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>
 +
====$xml-&gt;dispose( $node )====
 +
 +
Dispose and free the memory used by $node.
 +
 +
<div style='background-color: #e8e8f; 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: #e8e8f; 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: #e8e8f; 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: #e8e8f; 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: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 157: Line 317:
  
 
<!-- Pod2Wiki=item_make_document --></div>
 
<!-- Pod2Wiki=item_make_document --></div>
===$document = EPrints::XML::make_document()===
+
====$document = EPrints::XML::make_document()====
  
 
Create and return an empty document.
 
Create and return an empty document.
Line 167: Line 327:
  
 
<!-- Pod2Wiki=item_write_xml_file --></div>
 
<!-- Pod2Wiki=item_write_xml_file --></div>
===EPrints::XML::write_xml_file( $node, $filename )===
+
====EPrints::XML::write_xml_file( $node, $filename )====
  
 
Write the given XML node $node to file $filename.
 
Write the given XML node $node to file $filename.
Line 177: Line 337:
  
 
<!-- Pod2Wiki=item_write_xhtml_file --></div>
 
<!-- Pod2Wiki=item_write_xhtml_file --></div>
===EPrints::XML::write_xhtml_file( $node, $filename )===
+
====EPrints::XML::write_xhtml_file( $node, $filename )====
  
 
Write the given XML node $node to file $filename with an XHTML doctype.
 
Write the given XML node $node to file $filename with an XHTML doctype.
Line 187: Line 347:
  
 
<!-- Pod2Wiki=item_tidy --></div>
 
<!-- Pod2Wiki=item_tidy --></div>
===EPrints::XML::tidy( $domtree, { collapse=&gt;['element','element'...] }, [$indent] )===
+
====EPrints::XML::tidy( $domtree, { collapse=&gt;['element','element'...] }, [$indent] )====
  
 
Neatly indent the DOM tree.  
 
Neatly indent the DOM tree.  
Line 203: Line 363:
  
 
<!-- Pod2Wiki=item_namespace --></div>
 
<!-- Pod2Wiki=item_namespace --></div>
===$namespace = EPrints::XML::namespace( $thing, $version )===
+
====$namespace = EPrints::XML::namespace( $thing, $version )====
  
 
Return the namespace for the given version of the eprints xml.
 
Return the namespace for the given version of the eprints xml.
Line 213: Line 373:
  
 
<!-- Pod2Wiki=item_version --></div>
 
<!-- Pod2Wiki=item_version --></div>
===$v = EPrints::XML::version()===
+
====$v = EPrints::XML::version()====
  
 
Returns a string description of the current XML library and version.
 
Returns a string description of the current XML library and version.
 
<div style='background-color: #e8e8f; 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: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>

Revision as of 16:34, 12 February 2010


EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects


API: Core API

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


NAME

EPrints::XML - XML Abstraction Module

User Comments


For preference, use the methods in EPrints::Handle::XML

SYNOPSIS

 my $xml = $repository->xml;
 
 $doc = $xml->parse_string( $string );
 $doc = $xml->parse_file( $filename );
 $doc = $xml->parse_url( $url );
 
 $utf8_string = $xml->to_string( $dom_node, %opts );
 
 $dom_node = $xml->clone( $dom_node ); # deep
 $dom_node = $xml->clone_node( $dom_node ); # shallow
 
 # clone and return child nodes
 $dom_node = $xml->contents_of( $dom_node );
 # Return text child nodes as a string
 $utf8_string = $xml->text_contents_of( $dom_node );
 
 $dom_node = $xml->create_element( $name, %attr );
 $dom_node = $xml->create_text_node( $value );
 $dom_node = $xml->create_comment( $value );
 $dom_node = $xml->create_document_fragment;
 
 $xml->dispose( $dom_node );
 

head1 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


METHODS

User Comments


Parsing

User Comments


$doc = $xml->parse_string( $string, %opts )

Returns an XML document parsed from $string.

User Comments


$doc = $xml->parse_file( $filename, %opts )

Returns an XML document parsed from the file called $filename.

 base_path - base path to load DTD files from
 no_expand - don't expand entities
 

User Comments


$doc = $xml->parse_url( $url, %opts )

Returns an XML document parsed from the content located at $url.

User Comments


Node Creation

User Comments


$node = $xml->create_element( $name [, @attrs ] )

Returns a new XML element named $name with optional attribute pairs @attrs.

User Comments


$node = $xml->create_cdata_section( $value )

Returns a CDATA section containing $value.

User Comments


$node = $xml->create_text_node( $value )

Returns a new XML text node containing $value.

User Comments


$node = $xml->create_comment( $value )

Returns a new XML comment containing $value.

User Comments


$node = $xml->create_document_fragment

Returns a new XML document fragment.

User Comments


Other

User Comments


$bool = $xml->is( $node, $type [, $type ... ] )

Returns true if $node is one of the given node types: Document, DocumentFragment, Element, Comment, Text.

User Comments


$node = $xml->clone( $node )

Returns a deep clone of $node. The new node(s) will be owned by this object.

User Comments


$node = $xml->clone_node( $node )

Returns a clone of $node only (no children). The new node will be owned by this object.

User Comments


$node = EPrints::XML::clone_node( $node [, $deep ] )

DEPRECATED.

User Comments


$node = $xml->contents_of( $node )

Returns a document fragment containing a copy of all the children of $node.

User Comments


$string = $xml->text_contents_of( $node )

Returns the concantenated value of all text nodes in $node (or the value of $node if $node is a text node).

User Comments


$utf8_string = $xml->to_string( $node, %opts )

Serialises and returns the $node as a UTF-8 string.

To generate an XHTML string see EPrints::XHTML.

Options: indent - if true will indent the XML tree

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


$xml->dispose( $node )

Dispose and free the memory used by $node.

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


$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


$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