XML::Easy::NodeBasics(3pm) | User Contributed Perl Documentation | XML::Easy::NodeBasics(3pm) |
XML::Easy::NodeBasics - basic manipulation of XML data nodes
use XML::Easy::NodeBasics qw(xml_content_object xml_element); $content = xml_content_object("this", "&", "that"); $content = xml_content_object(@sublems); $element = xml_element("a", { href => "there" }, "there"); $element = xml_element("div", @subelems); use XML::Easy::NodeBasics qw( xml_c_content_object xml_c_content_twine); $content = xml_c_content_object($content); $twine = xml_c_content_twine($content); use XML::Easy::NodeBasics qw( xml_e_type_name xml_e_attributes xml_e_attribute xml_e_content_object); $type_name = xml_e_type_name($element); $attributes = xml_e_attributes($element); $href = xml_e_attribute($element, "href"); $content = xml_e_content_object($element); use XML::Easy::NodeBasics qw( xml_c_equal xml_e_equal xml_c_unequal xml_e_unequal); if(xml_c_equal($content0, $content1)) { ... if(xml_e_equal($element0, $element1)) { ... if(xml_c_unequal($content0, $content1)) { ... if(xml_e_unequal($element0, $element1)) { ...
This module supplies functions concerned with the creation, examination, and other manipulation of XML data nodes (content chunks and elements). The nodes are dumb data objects, best manipulated using plain functions such as the ones in this module.
The nodes are objects of the classes XML::Easy::Content and XML::Easy::Element. The data contained within an existing node cannot be modified. This means that references to nodes can be copied and passed around arbitrarily, without worrying about who might write to them, or deep versus shallow copying. As a result, tasks that you might think of as "modifying an XML node" actually involve creating a new node.
The node classes do not have any interesting object-oriented behaviour, and their minimalistic methods are not meant to be called directly. Instead, node creation and examination should be performed using the functions of this module.
For the purposes of examining what is contained within a chunk of content, there is a standard representation of content known as "twine". (It's stronger than a string, and has an alternating structure as will be described.)
A piece of twine is a reference to an array with an odd number of members. The first and last members, and all members in between with an even index, are strings giving the chunk's character data. Each member with an odd index is a reference to an XML::Easy::Element object, representing an XML element contained directly within the chunk. Any of the strings may be empty, if the chunk has no character data between subelements or at the start or end of the chunk.
When not looking inside a content chunk, it is preferred to represent it in encapsulated form as an XML::Easy::Content object.
Each function has two names. There is a longer descriptive name, and a shorter name to spare screen space and the programmer's fingers.
The construction functions each accept any number of items of XML content. These items may be supplied in any of several forms. Content item types may be mixed arbitrarily, in any sequence. The permitted forms of content item are:
The construction functions are:
All the supplied content items are concatenated to form a single chunk. The function returns a reference to an XML::Easy::Content object.
The returned array must not be subsequently modified. If possible, it will be marked as read-only in order to prevent modification.
All the attributes supplied are gathered together to form the element's attribute set. It is an error if an attribute name has been used more than once (even if the same value was given each time). All the supplied content items are concatenated to form the element's content. The function returns a reference to an XML::Easy::Element object.
The returned array must not be subsequently modified. If possible, it will be marked as read-only in order to prevent modification.
The returned hash must not be subsequently modified. If possible, it will be marked as read-only in order to prevent modification. As a side effect, the read-only-ness may make lookup of any non-existent attribute generate an exception rather than returning "undef".
The returned array must not be subsequently modified. If possible, it will be marked as read-only in order to prevent modification.
XML::Easy::Classify, XML::Easy::Content, XML::Easy::Element, XML::Easy::ProceduralWriter, XML::Easy::SimpleSchemaUtil, XML::Easy::Text
Andrew Main (Zefram) <zefram@fysh.org>
Copyright (C) 2009, 2010, 2011, 2017 Andrew Main (Zefram) <zefram@fysh.org>
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2022-10-20 | perl v5.36.0 |