{
    "mode": "perldoc",
    "parameter": "XML::LibXML::Text",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ALibXML%3A%3AText/json",
    "generated": "2026-06-09T13:40:16Z",
    "synopsis": "use XML::LibXML;\n# Only methods specific to Text nodes are listed here,\n# see the XML::LibXML::Node manpage for other methods\n$text = XML::LibXML::Text->new( $content );\n$nodedata = $text->data;\n$text->setData( $textcontent );\n$text->substringData($offset, $length);\n$text->appendData( $somedata );\n$text->insertData($offset, $string);\n$text->deleteData($offset, $length);\n$text->deleteDataString($remstring, $all);\n$text->replaceData($offset, $length, $string);\n$text->replaceDataString($old, $new, $flag);\n$text->replaceDataRegEx( $searchcond, $replacecond, $reflags );",
    "sections": {
        "NAME": {
            "content": "XML::LibXML::Text - XML::LibXML Class for Text Nodes\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use XML::LibXML;\n# Only methods specific to Text nodes are listed here,\n# see the XML::LibXML::Node manpage for other methods\n\n$text = XML::LibXML::Text->new( $content );\n$nodedata = $text->data;\n$text->setData( $textcontent );\n$text->substringData($offset, $length);\n$text->appendData( $somedata );\n$text->insertData($offset, $string);\n$text->deleteData($offset, $length);\n$text->deleteDataString($remstring, $all);\n$text->replaceData($offset, $length, $string);\n$text->replaceDataString($old, $new, $flag);\n$text->replaceDataRegEx( $searchcond, $replacecond, $reflags );\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Unlike the DOM specification, XML::LibXML implements the text node as the base class of all\ncharacter data node. Therefore there exists no CharacterData class. This allows one to apply\nmethods of text nodes also to Comments and CDATA-sections.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "The class inherits from XML::LibXML::Node. The documentation for Inherited methods is not listed\nhere.\n\nMany functions listed here are extensively documented in the DOM Level 3 specification\n(<http://www.w3.org/TR/DOM-Level-3-Core/>). Please refer to the specification for extensive\ndocumentation.\n\nnew\n$text = XML::LibXML::Text->new( $content );\n\nThe constructor of the class. It creates an unbound text node.\n\ndata\n$nodedata = $text->data;\n\nAlthough there exists the \"nodeValue\" attribute in the Node class, the DOM specification\ndefines data as a separate attribute. \"XML::LibXML\" implements these two attributes not as\ndifferent attributes, but as aliases, such as \"libxml2\" does. Therefore\n\n$text->data;\n\nand\n\n$text->nodeValue;\n\nwill have the same result and are not different entities.\n",
            "subsections": [
                {
                    "name": "setData",
                    "content": "$text->setData( $textcontent );\n\nThis function sets or replaces text content to a node. The node has to be of the type\n\"text\", \"cdata\" or \"comment\".\n"
                },
                {
                    "name": "substringData",
                    "content": "$text->substringData($offset, $length);\n\nExtracts a range of data from the node. (DOM Spec) This function takes the two parameters\n$offset and $length and returns the sub-string, if available.\n\nIf the node contains no data or $offset refers to an non-existing string index, this\nfunction will return *undef*. If $length is out of range \"substringData\" will return the\ndata starting at $offset instead of causing an error.\n"
                },
                {
                    "name": "appendData",
                    "content": "$text->appendData( $somedata );\n\nAppends a string to the end of the existing data. If the current text node contains no data,\nthis function has the same effect as \"setData\".\n"
                },
                {
                    "name": "insertData",
                    "content": "$text->insertData($offset, $string);\n\nInserts the parameter $string at the given $offset of the existing data of the node. This\noperation will not remove existing data, but change the order of the existing data.\n\nThe $offset has to be a positive value. If $offset is out of range, \"insertData\" will have\nthe same behaviour as \"appendData\".\n"
                },
                {
                    "name": "deleteData",
                    "content": "$text->deleteData($offset, $length);\n\nThis method removes a chunk from the existing node data at the given offset. The $length\nparameter tells, how many characters should be removed from the string.\n"
                },
                {
                    "name": "deleteDataString",
                    "content": "$text->deleteDataString($remstring, $all);\n\nThis method removes a chunk from the existing node data. Since the DOM spec is quite unhandy\nif you already know \"which\" string to remove from a text node, this method allows more\nperlish code :)\n\nThe functions takes two parameters: *$string* and optional the *$all* flag. If $all is not\nset, *undef* or *0*, \"deleteDataString\" will remove only the first occurrence of $string. If\n$all is *TRUE*\"deleteDataString\" will remove all occurrences of *$string* from the node\ndata.\n"
                },
                {
                    "name": "replaceData",
                    "content": "$text->replaceData($offset, $length, $string);\n\nThe DOM style version to replace node data.\n"
                },
                {
                    "name": "replaceDataString",
                    "content": "$text->replaceDataString($old, $new, $flag);\n\nThe more programmer friendly version of replaceData() :)\n\nInstead of giving offsets and length one can specify the exact string (*$oldstring*) to be\nreplaced. Additionally the *$all* flag allows one to replace all occurrences of\n*$oldstring*.\n"
                },
                {
                    "name": "replaceDataRegEx",
                    "content": "$text->replaceDataRegEx( $searchcond, $replacecond, $reflags );\n\nThis method replaces the node's data by a \"simple\" regular expression. Optional, this\nfunction allows one to pass some flags that will be added as flag to the replace statement.\n\n*NOTE:* This is a shortcut for\n\nmy $datastr = $node->getData();\n$datastr =~ s/somecond/replacement/g; # 'g' is just an example for any flag\n$node->setData( $datastr );\n\nThis function can make things easier to read for simple replacements. For more complex\nvariants it is recommended to use the code snippet above.\n"
                }
            ]
        },
        "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": []
        }
    },
    "summary": "XML::LibXML::Text - XML::LibXML Class for Text Nodes",
    "flags": [],
    "examples": [],
    "see_also": []
}