{
    "mode": "perldoc",
    "parameter": "XML::XPath::XMLParser",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/XML%3A%3AXPath%3A%3AXMLParser/json",
    "generated": "2026-06-11T23:51:16Z",
    "synopsis": "my $parser = XML::XPath::XMLParser->new(\nfilename => $self->getfilename,\nxml => $self->getxml,\nioref => $self->getioref,\nparser => $self->getparser,\n);\nmy $rootnode = $parser->parse;",
    "sections": {
        "NAME": {
            "content": "XML::XPath::XMLParser - The default XML parsing class that produces a node tree\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "my $parser = XML::XPath::XMLParser->new(\nfilename => $self->getfilename,\nxml => $self->getxml,\nioref => $self->getioref,\nparser => $self->getparser,\n);\nmy $rootnode = $parser->parse;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module generates a node tree for use as the context node for XPath processing. It aims to\nbe a quick parser, nothing fancy, and yet has to store more information than most parsers. To\nachieve this I've used array refs everywhere - no hashes. I don't have any performance figures\nfor the speedups achieved, so I make no apologies for anyone not used to using arrays instead of\nhashes. I think they make good sense here where we know the attributes of each type of node.\n",
            "subsections": []
        },
        "Node Structure": {
            "content": "All nodes have the same first 2 entries in the array: nodeparent and nodepos. The type of the\nnode is determined using the ref() function. The nodeparent always contains an entry for the\nparent of the current node - except for the root node which has undef in there. And nodepos is\nthe position of this node in the array that it is in (think: $node ==\n$node->[nodeparent]->[nodechildren]->[$node->[nodepos]] )\n\nNodes are structured as follows:\n",
            "subsections": [
                {
                    "name": "Root Node",
                    "content": "The root node is just an element node with no parent.\n\n[\nundef, # nodeparent - check for undef to identify root node\nundef, # nodepos\nundef, # nodeprefix\n[ ... ], # nodechildren (see below)\n]\n"
                },
                {
                    "name": "Element Node",
                    "content": "[\n$parent, # nodeparent\n<position in current array>, # nodepos\n'xxx', # nodeprefix - namespace prefix on this element\n[ ... ], # nodechildren\n'yyy', # nodename - element tag name\n[ ... ], # nodeattribs - attributes on this element\n[ ... ], # nodenamespaces - namespaces currently in scope\n]\n"
                },
                {
                    "name": "Attribute Node",
                    "content": "[\n$parent, # nodeparent - the element node\n<position in current array>, # nodepos\n'xxx', # nodeprefix - namespace prefix on this element\n'href', # nodekey - attribute name\n'ftp://ftp.com/', # nodevalue - value in the node\n]\n"
                },
                {
                    "name": "Namespace Nodes",
                    "content": "Each element has an associated set of namespace nodes that are currently in scope. Each\nnamespace node stores a prefix and the expanded name (retrieved from the xmlns:prefix=\"...\"\nattribute).\n\n[\n$parent,\n<pos>,\n'a', # nodeprefix - the namespace as it was written as a prefix\n'http://my.namespace.com', # nodeexpanded - the expanded name.\n]\n"
                },
                {
                    "name": "Text Nodes",
                    "content": "[\n$parent,\n<pos>,\n'This is some text' # nodetext - the text in the node\n]\n"
                },
                {
                    "name": "Comment Nodes",
                    "content": "[\n$parent,\n<pos>,\n'This is a comment' # nodecomment\n]\n"
                },
                {
                    "name": "Processing Instruction Nodes",
                    "content": "[\n$parent,\n<pos>,\n'target', # nodetarget\n'data', # nodedata\n]\n"
                }
            ]
        },
        "Usage": {
            "content": "If you feel the need to use this module outside of XML::XPath (for example you might use this\nmodule directly so that you can cache parsed trees), you can follow the following API:\n\nnew\nThe new method takes either no parameters, or any of the following parameters:\n\nfilename\nxml\nparser\nioref\n\nThis uses the familiar hash syntax, so an example might be:\n\nuse XML::XPath::XMLParser;\n\nmy $parser = XML::XPath::XMLParser->new(filename => 'example.xml');\n\nThe parameters represent a filename, a string containing XML, an XML::Parser instance and an\nopen filehandle ref respectively. You can also set or get all of these properties using the get\nand set functions that have the same name as the property: e.g. getfilename, setioref, etc.\n\nparse\nThe parse method generally takes no parameters, however you are free to pass either an open\nfilehandle reference or an XML string if you so require. The return value is a tree that\nXML::XPath can use. The parse method will die if there is an error in your XML, so be sure to\nuse perl's exception handling mechanism (eval{};) if you want to avoid this.\n\nparsefile\nThe parsefile method is identical to parse() except it expects a single parameter that is a\nstring naming a file to open and parse. Again it returns a tree and also dies if there are XML\nerrors.\n",
            "subsections": []
        },
        "NOTICES": {
            "content": "This file is distributed as part of the XML::XPath module, and is copyright 2000 Fastnet\nSoftware Ltd. Please see the documentation for the module as a whole for licencing information.\n",
            "subsections": []
        }
    },
    "summary": "XML::XPath::XMLParser - The default XML parsing class that produces a node tree",
    "flags": [],
    "examples": [],
    "see_also": []
}