{
    "content": [
        {
            "type": "text",
            "text": "# XML::LibXML::Reader (perldoc)\n\n## NAME\n\nXML::LibXML::Reader - XML::LibXML::Reader - interface to libxml2 pull parser\n\n## SYNOPSIS\n\nuse XML::LibXML::Reader;\nmy $reader = XML::LibXML::Reader->new(location => \"file.xml\")\nor die \"cannot read file.xml\\n\";\nwhile ($reader->read) {\nprocessNode($reader);\n}\nsub processNode {\nmy $reader = shift;\nprintf \"%d %d %s %d\\n\", ($reader->depth,\n$reader->nodeType,\n$reader->name,\n$reader->isEmptyElement);\n}\nor\nmy $reader = XML::LibXML::Reader->new(location => \"file.xml\")\nor die \"cannot read file.xml\\n\";\n$reader->preservePattern('//table/tr');\n$reader->finish;\nprint $reader->document->toString(1);\n\n## DESCRIPTION\n\nThis is a perl interface to libxml2's pull-parser implementation xmlTextReader\n*http://xmlsoft.org/html/libxml-xmlreader.html*. This feature requires at least libxml2-2.6.21.\nPull-parsers (such as StAX in Java, or XmlReader in C#) use an iterator approach to parse XML\ndocuments. They are easier to program than event-based parser (SAX) and much more lightweight\nthan tree-based parser (DOM), which load the complete tree into memory.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **CONSTRUCTOR** (2 subsections)\n- **METHODS CONTROLLING PARSING PROGRESS**\n- **METHODS EXTRACTING INFORMATION** (2 subsections)\n- **METHODS EXTRACTING DOM NODES**\n- **METHODS PROCESSING ATTRIBUTES**\n- **OTHER METHODS**\n- **DESTRUCTION**\n- **NODE TYPES**\n- **STATES**\n- **SEE ALSO**\n- **ORIGINAL IMPLEMENTATION**\n- **AUTHORS**\n- **VERSION**\n- **COPYRIGHT**\n- **LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "XML::LibXML::Reader",
        "section": "",
        "mode": "perldoc",
        "summary": "XML::LibXML::Reader - XML::LibXML::Reader - interface to libxml2 pull parser",
        "synopsis": "use XML::LibXML::Reader;\nmy $reader = XML::LibXML::Reader->new(location => \"file.xml\")\nor die \"cannot read file.xml\\n\";\nwhile ($reader->read) {\nprocessNode($reader);\n}\nsub processNode {\nmy $reader = shift;\nprintf \"%d %d %s %d\\n\", ($reader->depth,\n$reader->nodeType,\n$reader->name,\n$reader->isEmptyElement);\n}\nor\nmy $reader = XML::LibXML::Reader->new(location => \"file.xml\")\nor die \"cannot read file.xml\\n\";\n$reader->preservePattern('//table/tr');\n$reader->finish;\nprint $reader->document->toString(1);",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 28,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 27,
                "subsections": []
            },
            {
                "name": "CONSTRUCTOR",
                "lines": 11,
                "subsections": [
                    {
                        "name": "Source specification",
                        "lines": 13
                    },
                    {
                        "name": "Reader options",
                        "lines": 16
                    }
                ]
            },
            {
                "name": "METHODS CONTROLLING PARSING PROGRESS",
                "lines": 73,
                "subsections": []
            },
            {
                "name": "METHODS EXTRACTING INFORMATION",
                "lines": 36,
                "subsections": [
                    {
                        "name": "nodePath",
                        "lines": 6
                    },
                    {
                        "name": "matchesPattern",
                        "lines": 4
                    }
                ]
            },
            {
                "name": "METHODS EXTRACTING DOM NODES",
                "lines": 36,
                "subsections": []
            },
            {
                "name": "METHODS PROCESSING ATTRIBUTES",
                "lines": 64,
                "subsections": []
            },
            {
                "name": "OTHER METHODS",
                "lines": 57,
                "subsections": []
            },
            {
                "name": "DESTRUCTION",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "NODE TYPES",
                "lines": 22,
                "subsections": []
            },
            {
                "name": "STATES",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "ORIGINAL IMPLEMENTATION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "AUTHORS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "LICENSE",
                "lines": 3,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "XML::LibXML::Reader - XML::LibXML::Reader - interface to libxml2 pull parser\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use XML::LibXML::Reader;\n\n\n\nmy $reader = XML::LibXML::Reader->new(location => \"file.xml\")\nor die \"cannot read file.xml\\n\";\nwhile ($reader->read) {\nprocessNode($reader);\n}\n\n\n\nsub processNode {\nmy $reader = shift;\nprintf \"%d %d %s %d\\n\", ($reader->depth,\n$reader->nodeType,\n$reader->name,\n$reader->isEmptyElement);\n}\n\nor\n\nmy $reader = XML::LibXML::Reader->new(location => \"file.xml\")\nor die \"cannot read file.xml\\n\";\n$reader->preservePattern('//table/tr');\n$reader->finish;\nprint $reader->document->toString(1);\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This is a perl interface to libxml2's pull-parser implementation xmlTextReader\n*http://xmlsoft.org/html/libxml-xmlreader.html*. This feature requires at least libxml2-2.6.21.\nPull-parsers (such as StAX in Java, or XmlReader in C#) use an iterator approach to parse XML\ndocuments. They are easier to program than event-based parser (SAX) and much more lightweight\nthan tree-based parser (DOM), which load the complete tree into memory.\n\nThe Reader acts as a cursor going forward on the document stream and stopping at each node on\nthe way. At every point, the DOM-like methods of the Reader object allow one to examine the\ncurrent node (name, namespace, attributes, etc.)\n\nThe user's code keeps control of the progress and simply calls the \"read()\" function repeatedly\nto progress to the next node in the document order. Other functions provide means for skipping\ncomplete sub-trees, or nodes until a specific element, etc.\n\nAt every time, only a very limited portion of the document is kept in the memory, which makes\nthe API more memory-efficient than using DOM. However, it is also possible to mix Reader with\nDOM. At every point the user may copy the current node (optionally expanded into a complete\nsub-tree) from the processed document to another DOM tree, or to instruct the Reader to collect\nsub-document in form of a DOM tree consisting of selected nodes.\n\nReader API also supports namespaces, xml:base, entity handling, and DTD validation. Schema and\nRelaxNG validation support will probably be added in some later revision of the Perl interface.\n\nThe naming of methods compared to libxml2 and C# XmlTextReader has been changed slightly to\nmatch the conventions of XML::LibXML. Some functions have been changed or added with respect to\nthe C interface.\n",
                "subsections": []
            },
            "CONSTRUCTOR": {
                "content": "Depending on the XML source, the Reader object can be created with either of:\n\nmy $reader = XML::LibXML::Reader->new( location => \"file.xml\", ... );\nmy $reader = XML::LibXML::Reader->new( string => $xmlstring, ... );\nmy $reader = XML::LibXML::Reader->new( IO => $filehandle, ... );\nmy $reader = XML::LibXML::Reader->new( FD => fileno(STDIN), ... );\nmy $reader = XML::LibXML::Reader->new( DOM => $dom, ... );\n\nwhere ... are (optional) reader options described below in \"Reader options\" or various parser\noptions described in XML::LibXML::Parser. The constructor recognizes the following XML sources:\n",
                "subsections": [
                    {
                        "name": "Source specification",
                        "content": "location\nRead XML from a local file or URL.\n\nstring\nRead XML from a string.\n\nIO  Read XML a Perl IO filehandle.\n\nFD  Read XML from a file descriptor (bypasses Perl I/O layer, only applicable to filehandles for\nregular files or pipes). Possibly faster than IO.\n\nDOM Use reader API to walk through a pre-parsed XML::LibXML::Document.\n"
                    },
                    {
                        "name": "Reader options",
                        "content": "encoding => $encoding\noverride document encoding.\n\nRelaxNG => $rngschema\ncan be used to pass either a XML::LibXML::RelaxNG object or a filename or URL of a RelaxNG\nschema to the constructor. The schema is then used to validate the document as it is\nprocessed.\n\nSchema => $xsdschema\ncan be used to pass either a XML::LibXML::Schema object or a filename or URL of a W3C XSD\nschema to the constructor. The schema is then used to validate the document as it is\nprocessed.\n\n... the reader further supports various parser options described in XML::LibXML::Parser\n(specifically those labeled by /reader/).\n"
                    }
                ]
            },
            "METHODS CONTROLLING PARSING PROGRESS": {
                "content": "read ()\nMoves the position to the next node in the stream, exposing its properties.\n\nReturns 1 if the node was read successfully, 0 if there is no more nodes to read, or -1 in\ncase of error\n\nreadAttributeValue ()\nParses an attribute value into one or more Text and EntityReference nodes.\n\nReturns 1 in case of success, 0 if the reader was not positioned on an attribute node or all\nthe attribute values have been read, or -1 in case of error.\n\nreadState ()\nGets the read state of the reader. Returns the state value, or -1 in case of error. The\nmodule exports constants for the Reader states, see STATES below.\n\ndepth ()\nThe depth of the node in the tree, starts at 0 for the root node.\n\nnext ()\nSkip to the node following the current one in the document order while avoiding the sub-tree\nif any. Returns 1 if the node was read successfully, 0 if there is no more nodes to read, or\n-1 in case of error.\n\nnextElement (localname?,nsURI?)\nSkip nodes following the current one in the document order until a specific element is\nreached. The element's name must be equal to a given localname if defined, and its namespace\nmust equal to a given nsURI if defined. Either of the arguments can be undefined (or\nomitted, in case of the latter or both).\n\nReturns 1 if the element was found, 0 if there is no more nodes to read, or -1 in case of\nerror.\n\nnextPatternMatch (compiledpattern)\nSkip nodes following the current one in the document order until an element matching a given\ncompiled pattern is reached. See XML::LibXML::Pattern for information on compiled patterns.\nSee also the \"matchesPattern\" method.\n\nReturns 1 if the element was found, 0 if there is no more nodes to read, or -1 in case of\nerror.\n\nskipSiblings ()\nSkip all nodes on the same or lower level until the first node on a higher level is reached.\nIn particular, if the current node occurs in an element, the reader stops at the end tag of\nthe parent element, otherwise it stops at a node immediately following the parent node.\n\nReturns 1 if successful, 0 if end of the document is reached, or -1 in case of error.\n\nnextSibling ()\nIt skips to the node following the current one in the document order while avoiding the\nsub-tree if any.\n\nReturns 1 if the node was read successfully, 0 if there is no more nodes to read, or -1 in\ncase of error\n\nnextSiblingElement (name?,nsURI?)\nLike nextElement but only processes sibling elements of the current node (moving forward\nusing \"nextSibling ()\" rather than \"read ()\", internally).\n\nReturns 1 if the element was found, 0 if there is no more sibling nodes, or -1 in case of\nerror.\n\nfinish ()\nSkip all remaining nodes in the document, reaching end of the document.\n\nReturns 1 if successful, 0 in case of error.\n\nclose ()\nThis method releases any resources allocated by the current instance and closes any\nunderlying input. It returns 0 on failure and 1 on success. This method is automatically\ncalled by the destructor when the reader is forgotten, therefore you do not have to call it\ndirectly.\n",
                "subsections": []
            },
            "METHODS EXTRACTING INFORMATION": {
                "content": "name ()\nReturns the qualified name of the current node, equal to (Prefix:)LocalName.\n\nnodeType ()\nReturns the type of the current node. See NODE TYPES below.\n\nlocalName ()\nReturns the local name of the node.\n\nprefix ()\nReturns the prefix of the namespace associated with the node.\n\nnamespaceURI ()\nReturns the URI defining the namespace associated with the node.\n\nisEmptyElement ()\nCheck if the current node is empty, this is a bit bizarre in the sense that <a/> will be\nconsidered empty while <a></a> will not.\n\nhasValue ()\nReturns true if the node can have a text value.\n\nvalue ()\nProvides the text value of the node if present or undef if not available.\n\nreadInnerXml ()\nReads the contents of the current node, including child nodes and markup. Returns a string\ncontaining the XML of the node's content, or undef if the current node is neither an element\nnor attribute, or has no child nodes.\n\nreadOuterXml ()\nReads the contents of the current node, including child nodes and markup.\n\nReturns a string containing the XML of the node including its content, or undef if the\ncurrent node is neither an element nor attribute.\n",
                "subsections": [
                    {
                        "name": "nodePath",
                        "content": "Returns a canonical location path to the current element from the root node to the current\nnode. Namespaced elements are matched by '*', because there is no way to declare prefixes\nwithin XPath patterns. Unlike \"XML::LibXML::Node::nodePath()\", this function does not\nprovide sibling counts (i.e. instead of e.g. '/a/b[1]' and '/a/b[2]' you get '/a/b' for both\nmatches).\n"
                    },
                    {
                        "name": "matchesPattern",
                        "content": "Returns a true value if the current node matches a compiled pattern. See\nXML::LibXML::Pattern for information on compiled patterns. See also the \"nextPatternMatch\"\nmethod.\n"
                    }
                ]
            },
            "METHODS EXTRACTING DOM NODES": {
                "content": "document ()\nProvides access to the document tree built by the reader. This function can be used to\ncollect the preserved nodes (see \"preserveNode()\" and preservePattern).\n\nCAUTION: Never use this function to modify the tree unless reading of the whole document is\ncompleted!\n\ncopyCurrentNode (deep)\nThis function is similar a DOM function \"copyNode()\". It returns a copy of the currently\nprocessed node as a corresponding DOM object. Use deep = 1 to obtain the full sub-tree.\n\npreserveNode ()\nThis tells the XML Reader to preserve the current node in the document tree. A document tree\nconsisting of the preserved nodes and their content can be obtained using the method\n\"document()\" once parsing is finished.\n\nReturns the node or NULL in case of error.\n\npreservePattern (pattern,\\%nsmap)\nThis tells the XML Reader to preserve all nodes matched by the pattern (which is a streaming\nXPath subset). A document tree consisting of the preserved nodes and their content can be\nobtained using the method \"document()\" once parsing is finished.\n\nAn optional second argument can be used to provide a HASH reference mapping prefixes used by\nthe XPath to namespace URIs.\n\nThe XPath subset available with this function is described at\n\nhttp://www.w3.org/TR/xmlschema-1/#Selector\n\nand matches the production\n\nPath ::= ('.//')? ( Step '/' )* ( Step | '@' NameTest )\n\nReturns a positive number in case of success and -1 in case of error\n",
                "subsections": []
            },
            "METHODS PROCESSING ATTRIBUTES": {
                "content": "attributeCount ()\nProvides the number of attributes of the current node.\n\nhasAttributes ()\nWhether the node has attributes.\n\ngetAttribute (name)\nProvides the value of the attribute with the specified qualified name.\n\nReturns a string containing the value of the specified attribute, or undef in case of error.\n\ngetAttributeNs (localName, namespaceURI)\nProvides the value of the specified attribute.\n\nReturns a string containing the value of the specified attribute, or undef in case of error.\n\ngetAttributeNo (no)\nProvides the value of the attribute with the specified index relative to the containing\nelement.\n\nReturns a string containing the value of the specified attribute, or undef in case of error.\n\nisDefault ()\nReturns true if the current attribute node was generated from the default value defined in\nthe DTD.\n\nmoveToAttribute (name)\nMoves the position to the attribute with the specified local name and namespace URI.\n\nReturns 1 in case of success, -1 in case of error, 0 if not found\n\nmoveToAttributeNo (no)\nMoves the position to the attribute with the specified index relative to the containing\nelement.\n\nReturns 1 in case of success, -1 in case of error, 0 if not found\n\nmoveToAttributeNs (localName,namespaceURI)\nMoves the position to the attribute with the specified local name and namespace URI.\n\nReturns 1 in case of success, -1 in case of error, 0 if not found\n\nmoveToFirstAttribute ()\nMoves the position to the first attribute associated with the current node.\n\nReturns 1 in case of success, -1 in case of error, 0 if not found\n\nmoveToNextAttribute ()\nMoves the position to the next attribute associated with the current node.\n\nReturns 1 in case of success, -1 in case of error, 0 if not found\n\nmoveToElement ()\nMoves the position to the node that contains the current attribute node.\n\nReturns 1 in case of success, -1 in case of error, 0 if not moved\n\nisNamespaceDecl ()\nDetermine whether the current node is a namespace declaration rather than a regular\nattribute.\n\nReturns 1 if the current node is a namespace declaration, 0 if it is a regular attribute or\nother type of node, or -1 in case of error.\n",
                "subsections": []
            },
            "OTHER METHODS": {
                "content": "lookupNamespace (prefix)\nResolves a namespace prefix in the scope of the current element.\n\nReturns a string containing the namespace URI to which the prefix maps or undef in case of\nerror.\n\nencoding ()\nReturns a string containing the encoding of the document or undef in case of error.\n\nstandalone ()\nDetermine the standalone status of the document being read. Returns 1 if the document was\ndeclared to be standalone, 0 if it was declared to be not standalone, or -1 if the document\ndid not specify its standalone status or in case of error.\n\nxmlVersion ()\nDetermine the XML version of the document being read. Returns a string containing the XML\nversion of the document or undef in case of error.\n\nbaseURI ()\nReturns the base URI of a given node.\n\nisValid ()\nRetrieve the validity status from the parser.\n\nReturns 1 if valid, 0 if no, and -1 in case of error.\n\nxmlLang ()\nThe xml:lang scope within which the node resides.\n\nlineNumber ()\nProvide the line number of the current parsing point.\n\ncolumnNumber ()\nProvide the column number of the current parsing point.\n\nbyteConsumed ()\nThis function provides the current index of the parser relative to the start of the current\nentity. This function is computed in bytes from the beginning starting at zero and finishing\nat the size in bytes of the file if parsing a file. The function is of constant cost if the\ninput is UTF-8 but can be costly if run on non-UTF-8 input.\n\nsetParserProp (prop => value, ...)\nChange the parser processing behaviour by changing some of its internal properties. The\nfollowing properties are available with this function: ``loadextdtd'',\n``completeattributes'', ``validation'', ``expandentities''.\n\nSince some of the properties can only be changed before any read has been done, it is best\nto set the parsing properties at the constructor.\n\nReturns 0 if the call was successful, or -1 in case of error\n\ngetParserProp (prop)\nGet value of an parser internal property. The following property names can be used:\n``loadextdtd'', ``completeattributes'', ``validation'', ``expandentities''.\n\nReturns the value, usually 0 or 1, or -1 in case of error.\n",
                "subsections": []
            },
            "DESTRUCTION": {
                "content": "XML::LibXML takes care of the reader object destruction when the last reference to the reader\nobject goes out of scope. The document tree is preserved, though, if either of $reader->document\nor $reader->preserveNode was used and references to the document tree exist.\n",
                "subsections": []
            },
            "NODE TYPES": {
                "content": "The reader interface provides the following constants for node types (the constant symbols are\nexported by default or if tag \":types\" is used).\n\nXMLREADERTYPENONE                    => 0\nXMLREADERTYPEELEMENT                 => 1\nXMLREADERTYPEATTRIBUTE               => 2\nXMLREADERTYPETEXT                    => 3\nXMLREADERTYPECDATA                   => 4\nXMLREADERTYPEENTITYREFERENCE        => 5\nXMLREADERTYPEENTITY                  => 6\nXMLREADERTYPEPROCESSINGINSTRUCTION  => 7\nXMLREADERTYPECOMMENT                 => 8\nXMLREADERTYPEDOCUMENT                => 9\nXMLREADERTYPEDOCUMENTTYPE           => 10\nXMLREADERTYPEDOCUMENTFRAGMENT       => 11\nXMLREADERTYPENOTATION                => 12\nXMLREADERTYPEWHITESPACE              => 13\nXMLREADERTYPESIGNIFICANTWHITESPACE  => 14\nXMLREADERTYPEENDELEMENT             => 15\nXMLREADERTYPEENDENTITY              => 16\nXMLREADERTYPEXMLDECLARATION         => 17\n",
                "subsections": []
            },
            "STATES": {
                "content": "The following constants represent the values returned by \"readState()\". They are exported by\ndefault, or if tag \":states\" is used:\n\nXMLREADERNONE      => -1\nXMLREADERSTART     =>  0\nXMLREADERELEMENT   =>  1\nXMLREADEREND       =>  2\nXMLREADEREMPTY     =>  3\nXMLREADERBACKTRACK =>  4\nXMLREADERDONE      =>  5\nXMLREADERERROR     =>  6\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "XML::LibXML::Pattern for information about compiled patterns.\n\nhttp://xmlsoft.org/html/libxml-xmlreader.html\n\nhttp://dotgnu.org/pnetlib-doc/System/Xml/XmlTextReader.html\n",
                "subsections": []
            },
            "ORIGINAL IMPLEMENTATION": {
                "content": "Heiko Klein, <H.Klein@gmx.net<gt> and Petr Pajas\n",
                "subsections": []
            },
            "AUTHORS": {
                "content": "Matt Sergeant, Christian Glahn, Petr Pajas\n",
                "subsections": []
            },
            "VERSION": {
                "content": "2.0134\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "2001-2007, AxKit.com Ltd.\n\n2002-2006, Christian Glahn.\n\n2006-2009, Petr Pajas.\n",
                "subsections": []
            },
            "LICENSE": {
                "content": "This program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
                "subsections": []
            }
        }
    }
}