.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "XML::Struct 3pm"
.TH XML::Struct 3pm "2019-02-21" "perl v5.28.1" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
XML\-Struct \- Represent XML as data structure preserving element order
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use XML::Struct qw(readXML writeXML simpleXML);
\&
\& my $xml = readXML( "input.xml" );
\& # [ root => { xmlns => \*(Aqhttp://example.org/\*(Aq }, [ \*(Aq!\*(Aq, [ x => {}, [42] ] ] ]
\&
\& my $doc = writeXML( $xml );
\& #
\& # !42
\&
\& my $simple = simpleXML( $xml, root => \*(Aqrecord\*(Aq );
\& # { record => { xmlns => \*(Aqhttp://example.org/\*(Aq, x => 42 } }
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
XML::Struct implements a mapping between \s-1XML\s0 and Perl data structures. By
default, the mapping preserves element order, so it also suits for
\&\*(L"document-oriented\*(R" \s-1XML.\s0 In short, an \s-1XML\s0 element is represented as array
reference with three parts:
.PP
.Vb 1
\& [ $name => \e%attributes, \e@children ]
.Ve
.PP
This data structure corresponds to the abstract data model of
MicroXML , a simplified subset of \s-1XML.\s0
.PP
If your \s-1XML\s0 documents don't contain relevant attributes, you can also choose
to map to this format:
.PP
.Vb 2
\& [ $name => \e@children ] # element without attributes
\& [ $name ] # empty tag without attributes
.Ve
.PP
Both parsing (with XML::Struct::Reader or function \f(CW\*(C`readXML\*(C'\fR) and
serializing (with XML::Struct::Writer or function \f(CW\*(C`writeXML\*(C'\fR) are fully
based on XML::LibXML, so performance is better than XML::Simple and
similar to XML::LibXML::Simple.
.SH "MODULES"
.IX Header "MODULES"
.IP "XML::Struct::Reader" 4
.IX Item "XML::Struct::Reader"
Parse \s-1XML\s0 as stream into \s-1XML\s0 data structures.
.IP "XML::Struct::Writer" 4
.IX Item "XML::Struct::Writer"
Write \s-1XML\s0 data structures to \s-1XML\s0 streams for serializing, \s-1SAX\s0 processing, or
creating a \s-1DOM\s0 object.
.IP "XML::Struct::Writer::Stream" 4
.IX Item "XML::Struct::Writer::Stream"
Simplified \s-1SAX\s0 handler for \s-1XML\s0 serialization.
.IP "XML::Struct::Simple" 4
.IX Item "XML::Struct::Simple"
Transform \s-1XML\s0 data structure into simple form.
.SH "FUNCTIONS"
.IX Header "FUNCTIONS"
The following functions are exported on request:
.ie n .SS "readXML( $source [, %options ] )"
.el .SS "readXML( \f(CW$source\fP [, \f(CW%options\fP ] )"
.IX Subsection "readXML( $source [, %options ] )"
Read an \s-1XML\s0 document with XML::Struct::Reader. The type of source (string,
filename, \s-1URL, IO\s0 Handle...) is detected automatically. See
XML::Struct::Reader for options. Options not known to XML::Struct::Reader
are passed to XML::LibXML::Reader.
.ie n .SS "writeXML( $xml [, %options ] )"
.el .SS "writeXML( \f(CW$xml\fP [, \f(CW%options\fP ] )"
.IX Subsection "writeXML( $xml [, %options ] )"
Write an \s-1XML\s0 document/element with XML::Struct::Writer. See
XML::Struct::Writer for options.
.ie n .SS "simpleXML( $element [, %options ] )"
.el .SS "simpleXML( \f(CW$element\fP [, \f(CW%options\fP ] )"
.IX Subsection "simpleXML( $element [, %options ] )"
Transform an \s-1XML\s0 document/element into simple key-value format as known from
XML::Simple. See XML::Struct::Simple for options.
.ie n .SS "removeXMLAttr( $element )"
.el .SS "removeXMLAttr( \f(CW$element\fP )"
.IX Subsection "removeXMLAttr( $element )"
Transform \s-1XML\s0 structure with attributes to \s-1XML\s0 structure without attributes.
The function does not modify the passed element but creates a modified copy.
.PP
\&\fIthis function is deprecated and will be removed in a future release!\fR
.SH "EXAMPLE"
.IX Header "EXAMPLE"
To give an example, with XML::Struct::Reader, this \s-1XML\s0 document:
.PP
.Vb 7
\&
\& text
\&
\& text
\&
\&
\&
.Ve
.PP
is transformed to this structure:
.PP
.Vb 9
\& [
\& "root", { }, [
\& [ "foo", { }, "text" ],
\& [ "bar", { key => "value" }, [
\& "text",
\& [ "doz", { }, [ ] ]
\& ]
\& ]
\& ]
.Ve
.PP
This module also supports a simple key-value (aka \*(L"data-oriented\*(R") format, as
used by XML::Simple. With option \f(CW\*(C`simple\*(C'\fR (or function \f(CW\*(C`simpleXML\*(C'\fR) the
document given above would be transformed to this structure:
.PP
.Vb 7
\& {
\& foo => "text",
\& bar => {
\& key => "value",
\& doz => {}
\& }
\& }
.Ve
.SH "SEE ALSO"
.IX Header "SEE ALSO"
This module was first created to be used in Catmandu::XML and turned out to
also become a replacement for XML::Simple. See the former for more \s-1XML\s0
processing.
.PP
XML::Twig is another popular and powerfull module for stream-based
processing of \s-1XML\s0 documents.
.PP
See XML::Smart, XML::Hash::LX, XML::Parser::Style::ETree,
XML::Fast, and XML::Structured for different representations of \s-1XML\s0 data
as data structures (feel free to implement converters from/to XML::Struct).
XML::GenericJSON seems to be an outdated and incomplete attempt to capture
more parts of \s-1XML\s0 Infoset in another data structure.
.PP
See JSONx for a kind of reverse direction (\s-1JSON\s0 in \s-1XML\s0).
.SH "COPYRIGHT AND LICENSE"
.IX Header "COPYRIGHT AND LICENSE"
This software is copyright (c) 2014 by Jakob Vo\*8.
.PP
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.