Document tree API.
More...
A buffer structure, this old construct is limited to 2GB and is being deprecated, use API with
xmlBuf instead.
More...
List structure used when there is an enumeration in DTDs.
More...
An Attribute declaration in a DTD.
More...
An XML Element content as stored after parsing an element definition in a DTD.
More...
An XML Element declaration from a DTD.
More...
An XML DTD, as defined by <!DOCTYPE ... There is actually one for the internal subset and for the external subset.
More...
Generic node type in an XML or HTML tree.
More...
Context for DOM wrapper-operations.
More...
#define
XML_XML_NAMESPACE (const
xmlChar *) "http://www.w3.org/XML/1998/namespace"
This is the namespace for the special xml: prefix predefined in the XML Namespace specification.
#define
XML_XML_ID (const
xmlChar *) "xml:id"
This is the name for the special xml:id attribute.
A namespace declaration node.
Macro for compatibility naming layer with libxml1.
Macro for compatibility naming layer with libxml1.
Parser input buffer.
Output buffer.
Parser input.
Parser context.
SAX locator.
SAX handler.
Entity declaration.
Buffer type.
typedef struct _xmlBuf
xmlBuf
Buffer with 64-bit support.
Notation declaration.
Enumeration in a DTD.
Attribute declaration.
Element content in element declarations.
Element declaration.
Namespace declaration.
Document type definition (DTD)
Attribute of an element.
Extra data for ID attributes.
Generic node type in an XML or HTML tree.
XML or HTML document.
Context for DOM wrapper operations.
A function called to acquire namespaces (
xmlNs) from the wrapper.
Signature for the registration callback of a created node.
Signature for the deregistration callback of a discarded node.
Removed, buffers always use XML_BUFFER_ALLOC_IO now.
The different element types carried by an XML tree.
More...
A DTD Attribute type definition.
A DTD Attribute default definition.
Possible definitions of element content types.
Possible definitions of element content occurrences.
The different possibilities for an element content type.
Set of properties of the document as found by the parser.
More...
Check that a value conforms to the lexical space of NCName.
Check that a value conforms to the lexical space of QName.
Check that a value conforms to the lexical space of Name.
Check that a value conforms to the lexical space of NMToken.
Build a QName from prefix and local name.
Parse an XML qualified name.
Parse an XML qualified name.
Create a DTD node.
Create a DTD node.
Get the internal subset of a document.
Free a DTD structure.
Create a new namespace.
Free a list of
xmlNs objects.
Creates a new XML document.
Free a document including all children and associated DTDs.
Create an attribute node.
Create an attribute node.
Create an attribute node.
Create an attribute node.
Free an attribute list including all children.
Free an attribute including all children.
Create a copy of the attribute.
Create a copy of an attribute list.
Copy a DTD.
Copy a document.
Create an element node.
Create an element node.
Create an element node.
Create an element node.
Create a new child element and append it to a parent element.
Create a new text node.
Create a text node.
Create a processing instruction object.
Create a processing instruction node.
Create a new text node.
Create a new text node.
Create a comment node.
Create a CDATA section node.
Create an empty entity reference node.
Create a new entity reference node, linking the result with the entity in doc if found.
Copy a node.
Copy a node into another document.
Copy a node list and all children into a new document.
Copy a node list and all children.
Create a new child element and append it to a parent element.
Create an element node.
Create a document fragment node.
Get line number of node.
Build a structure based Path for the given node.
Get the root element of the document.
Find the last child of a node.
Check whether the node is a text node.
Checks whether this node is an empty or whitespace-only text node.
If root is NULL no action is taken.
Set (or reset) the name of a node.
Unlink cur and append it to the children of parent.
Append a node list to another node.
Unlink the old node.
Unlinks cur and inserts it as previous sibling before next.
Unlinks cur and inserts it as last sibling of node.
Unlinks cur and inserts it as next sibling after prev.
Unlink a node from its tree.
Merge the second text node into the first.
Concat the given string at the end of the existing node content.
Free a node list including all children.
Free a node including all the children.
Associate all nodes in a tree with a new document.
Associate all subtrees in list with a new document.
Search for a namespace with prefix in scope of node.
Search for a namespace matching URI in scope of node.
Find all in-scope namespaces of a node.
Find all in-scope namespaces of a node.
Set the namespace of an element or attribute node.
Copy a namespace.
Copy a namespace list.
Set (or reset) an element's attribute.
Set (or reset) an element's attribute.
Look up the value of an element's attribute.
Look up the value of an element's attribute.
Look up the value of an element's attribute.
Search for an attribute of an element.
Search for an attribute of an element.
Look up the value of an element's attribute.
Parse an attribute value and build a node list with text and entity reference nodes.
Serializes attribute children (text and entity reference nodes) into a string.
Serializes attribute children (text and entity reference nodes) into a string.
Replace the text content of a node.
Append the extra substring to the node content.
Append the extra substring to the node content.
Returns the string value of a node.
Append the string value of a node to buffer.
Append the string value of a node to buf.
Find the xml:lang of a node.
Find the xml:space of a node.
Set the xml:lang attribute of a node.
Set the xml:space attribute of a node.
Searches for the base URI.
Set (or reset) the base URI of a node, i.e.
Unlink and free an attribute including all children.
Remove an attribute of an element.
Remove an attribute of an element.
This function checks that all the namespaces declared within the given tree are properly declared.
Serialize an XML document to memory.
Serialize an XML document to a FILE.
Serialize an XML document to a FILE.
Serialize an XML node to a FILE.
Serialize an XML node to an
xmlBuf.
Serialize an XML document to an output buffer.
Serialize an XML node to an output buffer.
Serialize an XML document to a file using the given encoding.
Try to find if the document correspond to an XHTML DTD.
Get the compression level of a document, ZLIB based.
Set the compression level of a document, ZLIB based.
Get the global compression level, ZLIB based.
Set the global compression level, ZLIB based.
Allocates and initializes a new DOM-wrapper context.
Frees the DOM-wrapper context.
Fix up namespaces.
Fix up namespaces before moving a node.
Unlinks the given node from its owner.
Clone a node and fix namespaces.
Count the number of child nodes which are elements.
Find the closest following sibling which is a element.
Find the first child node which is an element.
Find the last child node which is an element.
Find the closest preceding sibling which is a element.
Registers a callback for node creation.
Registers a callback for node destruction.
Set per-thread default value.
Set per-thread default value.
Set the buffer allocation scheme.
Get the buffer allocation scheme.
Create a buffer.
Create a buffer with an initial size.
Create a static buffer.
Resize a buffer to a minimum size.
Free a buffer.
Dump a buffer to a FILE.
Append bytes to a buffer.
Prepend bytes to a buffer.
Append a zero-terminated string to a buffer.
Append a zero-terminated C string to a buffer.
Discard bytes at the start of a buffer.
Grow a buffer.
Empty a buffer.
Get pointer into buffer content.
Extract buffer content.
Set the allocation scheme of a buffer.
Get the size of the buffer content.
Append a zero-terminated
xmlChar string to a buffer.
Append a zero-terminated C string to a buffer.
Append a quoted string to a buffer.
Get pointer into buffer content.
Return a pointer to the end of the buffer content.
Return the size of the buffer content.
Discard bytes at the start of a buffer.
Document tree API.
Data structures and functions to build, modify, query and serialize XML and HTML document trees. Also contains the buffer API.
- Copyright
- See Copyright for the status of this software.
- Author
- Daniel Veillard
◆ LIBXML2_NEW_BUFFER
#define LIBXML2_NEW_BUFFER
◆ xmlChildrenNode
#define xmlChildrenNode children
Macro for compatibility naming layer with libxml1.
Maps to "children."
◆ xmlRootNode
#define xmlRootNode children
Macro for compatibility naming layer with libxml1.
Maps to "children".
◆ xmlDeregisterNodeFunc
typedef void(* xmlDeregisterNodeFunc) (
xmlNode *node)
Signature for the deregistration callback of a discarded node.
- Parameters
-
node the current node
◆ xmlDOMWrapAcquireNsFunction
A function called to acquire namespaces (xmlNs) from the wrapper.
- Parameters
-
ctxt a DOM wrapper context
node the context node (element or attribute)
nsName the requested namespace name
nsPrefix the requested namespace prefix
- Returns
- an xmlNs or NULL in case of an error.
◆ xmlParserInputBuffer
Parser input buffer.
This struct and all related functions should ultimately be removed from the public interface.
◆ xmlRegisterNodeFunc
typedef void(* xmlRegisterNodeFunc) (
xmlNode *node)
Signature for the registration callback of a created node.
- Parameters
-
node the current node
◆ xmlDocProperties
Set of properties of the document as found by the parser.
Some of them are linked to similarly named xmlParserOption.
| Enumerator |
|---|
| XML_DOC_WELLFORMED | document is XML well formed
|
| XML_DOC_NSVALID | document is Namespace valid
|
| XML_DOC_OLD10 | parsed with old XML-1.0 parser
|
| XML_DOC_DTDVALID | DTD validation was successful.
|
| XML_DOC_XINCLUDE | XInclude substitution was done.
|
| XML_DOC_USERBUILT | Document was built using the API and not by parsing an instance.
|
| XML_DOC_INTERNAL | built for internal processing
|
| XML_DOC_HTML | parsed or built HTML document
|
◆ xmlElementType
The different element types carried by an XML tree.
NOTE: This is synchronized with DOM Level 1 values. See http://www.w3.org/TR/REC-DOM-Level-1/
Actually this had diverged a bit, and XML_DTD_NODE is used instead of XML_DOCUMENT_TYPE_NODE.
| Enumerator |
|---|
| XML_ELEMENT_NODE | An element.
Objects of this type are an xmlNode.
|
| XML_ATTRIBUTE_NODE | An attribute.
Objects of this type are an xmlAttr.
|
| XML_TEXT_NODE | A text node.
Objects of this type are an xmlNode.
|
| XML_CDATA_SECTION_NODE | A CDATA section.
Objects of this type are an xmlNode.
|
| XML_ENTITY_REF_NODE | An entity reference.
Objects of this type are an xmlNode. The children member points to the entity declaration if available.
|
| XML_ENTITY_NODE | unused
|
| XML_PI_NODE | A processing instruction.
Objects of this type are an xmlNode.
|
| XML_COMMENT_NODE | A comment.
Objects of this type are an xmlNode.
|
| XML_DOCUMENT_NODE | A document.
Objects of this type are an xmlDoc.
|
| XML_DOCUMENT_TYPE_NODE | unused
|
| XML_DOCUMENT_FRAG_NODE | A document fragment.
Objects of this type are an xmlNode.
|
| XML_NOTATION_NODE | A notation, unused.
|
| XML_HTML_DOCUMENT_NODE | An HTML document.
Objects of this type are an xmlDoc.
|
| XML_DTD_NODE | A document type definition.
Objects of this type are an xmlDtd.
|
| XML_ELEMENT_DECL | An element declaration.
Objects of this type are an xmlElement.
|
| XML_ATTRIBUTE_DECL | An attribute declaration.
Objects of this type are an xmlAttribute.
|
| XML_ENTITY_DECL | An entity declaration.
Objects of this type are an xmlEntity.
|
| XML_NAMESPACE_DECL | An XPath namespace node.
Can only be returned by the XPath engine. Objects of this type are an xmlNs which has a completely different layout than xmlNode. The next member contains a pointer to the xmlNode element to which the namespace applies.
Nodes of this type must be handled with extreme care to avoid type confusion bugs.
|
| XML_XINCLUDE_START | An XInclude start marker.
Objects of this type are an xmlNode. Inserted as preceding sibling of XIncluded content.
|
| XML_XINCLUDE_END | An XInclude end marker.
Objects of this type are an xmlNode. Inserted as following sibling of XIncluded content.
|
◆ xmlAddChild()
Unlink cur and append it to the children of parent.
If cur is a text node, it may be merged with an adjacent text node and freed. In this case the text node containing the merged content is returned.
If cur is an attribute node, it is appended to the attributes of parent. If the attribute list contains an attribute with a name matching cur, the old attribute is destroyed.
Before version 2.13, this function didn't unlink cur before moving it. Callers must unlink the node manually if it has siblings.
General notes:
Move operations like xmlAddChild can cause element or attribute nodes to reference namespaces that aren't declared in one of their ancestors. This can lead to use-after-free errors if the elements containing the declarations are freed later, especially when moving nodes from one document to another. You should consider calling xmlReconciliateNs after a move operation to normalize namespaces. Another option is to call xmlDOMWrapAdoptNode with the target parent before moving a node.
For the most part, move operations don't check whether the resulting tree structure is valid. Users must make sure that parent nodes only receive children of valid types. Inserted child nodes must never be an ancestor of the parent node to avoid cycles in the tree structure. In general, only document, document fragments, elements and attributes should be used as parent nodes.
When moving a node between documents and a memory allocation fails, the node's content will be corrupted and it will be unlinked. In this case, the node must be freed manually.
Moving DTDs between documents isn't supported.
- Parameters
-
parent the parent node
cur the child node
- Returns
- cur or a sibling if cur was merged. Returns NULL if arguments are invalid or a memory allocation failed.
◆ xmlAddChildList()
Append a node list to another node.
See xmlAddChild.
- Parameters
-
parent the parent node
cur the first node in the list
- Returns
- the last child or NULL in case of error.
◆ xmlAddNextSibling()
Unlinks cur and inserts it as next sibling after prev.
Unlike xmlAddChild this function does not merge text nodes.
If cur is an attribute node, it is inserted after attribute prev. If the attribute list contains an attribute with a name matching cur, the old attribute is destroyed.
See the notes in xmlAddChild.
- Parameters
-
prev the target node
cur the new node
- Returns
- cur or a sibling if cur was merged. Returns NULL if arguments are invalid or a memory allocation failed.
◆ xmlAddPrevSibling()
Unlinks cur and inserts it as previous sibling before next.
Unlike xmlAddChild this function does not merge text nodes.
If cur is an attribute node, it is inserted before attribute next. If the attribute list contains an attribute with a name matching cur, the old attribute is destroyed.
See the notes in xmlAddChild.
- Parameters
-
next the target node
cur the new node
- Returns
- cur or a sibling if cur was merged. Returns NULL if arguments are invalid or a memory allocation failed.
◆ xmlAddSibling()
Unlinks cur and inserts it as last sibling of node.
If cur is a text node, it may be merged with an adjacent text node and freed. In this case the text node containing the merged content is returned.
If cur is an attribute node, it is appended to the attribute list containing node. If the attribute list contains an attribute with a name matching cur, the old attribute is destroyed.
See the notes in xmlAddChild.
- Parameters
-
node the target node
cur the new node
- Returns
- cur or a sibling if cur was merged. Returns NULL if arguments are invalid or a memory allocation failed.
◆ xmlAttrSerializeTxtContent()
void xmlAttrSerializeTxtContent
(
xmlBuffer *
buf,
Serialize attribute text to an xmlBuffer.
- Parameters
-
buf the XML buffer output
doc the document
attr the attribute node
string the text content
◆ xmlBufContent()
Get pointer into buffer content.
- Parameters
-
buf the buffer
- Returns
- the internal content or NULL in case of error
◆ xmlBufEnd()
Return a pointer to the end of the buffer content.
- Parameters
-
buf the buffer
- Returns
- the end of the internal content or NULL in case of error
◆ xmlBufferAdd()
Append bytes to a buffer.
If len is -1, str is assumed to be zero-terminated.
- Parameters
-
buf the buffer
str bytes to add
len number of bytes
- Returns
- an xmlParserErrors code.
◆ xmlBufferAddHead()
Prepend bytes to a buffer.
If len is -1, str is assumed to be zero-terminated.
- Parameters
-
buf the buffer
str bytes to prepend
len number of bytes
- Returns
- an xmlParserErrors code.
◆ xmlBufferCat()
Append a zero-terminated string to a buffer.
- Parameters
-
buf the buffer
str string to add
- Returns
- an xmlParserErrors code.
◆ xmlBufferCCat()
Append a zero-terminated C string to a buffer.
- Parameters
-
buf the buffer
str string to add
- Returns
- an xmlParserErrors code.
◆ xmlBufferContent()
Get pointer into buffer content.
- Parameters
-
buf the buffer
- Returns
- the internal content
◆ xmlBufferCreate()
Create a buffer.
The default initial size is 256.
- Returns
- the new structure.
◆ xmlBufferCreateSize()
xmlBuffer * xmlBufferCreateSize
(
size_t
size )
Create a buffer with an initial size.
- Parameters
-
size initial size of buffer
- Returns
- the new structure.
◆ xmlBufferCreateStatic()
xmlBuffer * xmlBufferCreateStatic
(
void *
mem,
size_t size )
Create a static buffer.
The memory must be zero-terminated and not be modified for the lifetime of the buffer. A static buffer can't be grown, modified or detached, but it can be shrunk.
- Parameters
-
mem the memory area
size the size in bytes
- Returns
- a new buffer
◆ xmlBufferDetach()
Extract buffer content.
Return the contents of the buffer as an xmlChar string, clearing the buffer.
This doesn't work with static buffers as they can't be reset.
- Parameters
-
buf the buffer
- Returns
- the buffer content
◆ xmlBufferDump()
int xmlBufferDump
(
FILE * file,
Dump a buffer to a FILE.
- Parameters
-
file the output file
buf the buffer
- Returns
- the number of bytes written
◆ xmlBufferEmpty()
Empty a buffer.
- Parameters
-
buf the buffer
◆ xmlBufferFree()
Free a buffer.
- Parameters
-
buf the buffer to free
◆ xmlBufferGrow()
Grow a buffer.
- Deprecated
- Internal function, don't use.
- Parameters
-
buf the buffer
len number of extra bytes to allocate
- Returns
- the new available space or -1 in case of error
◆ xmlBufferLength()
int xmlBufferLength
(
const
xmlBuffer *
buf )
Get the size of the buffer content.
- Parameters
-
buf the buffer
- Returns
- the size of the buffer content in bytes
◆ xmlBufferResize()
Resize a buffer to a minimum size.
- Deprecated
- Internal function, don't use.
- Parameters
-
buf the buffer to resize
size the desired size
- Returns
- 1 on succes, 0 in case of error
◆ xmlBufferSetAllocationScheme()
void xmlBufferSetAllocationScheme
(
xmlBuffer *
buf,
Set the allocation scheme of a buffer.
For libxml2 before 2.14, it is recommended to set this to XML_BUFFER_ALLOC_DOUBLE_IT. Has no effect on 2.14 or later.
- Parameters
-
buf the buffer to tune
scheme allocation scheme to use
◆ xmlBufferShrink()
Discard bytes at the start of a buffer.
- Deprecated
- Internal function, don't use.
- Parameters
-
buf the buffer
len the number of bytes to remove
- Returns
- the number of bytes removed, or -1 in case of failure.
◆ xmlBufferWriteCHAR()
Append a zero-terminated xmlChar string to a buffer.
- Parameters
-
buf the XML buffer
string the string to add
◆ xmlBufferWriteChar()
Append a zero-terminated C string to a buffer.
Same as xmlBufferCCat.
- Parameters
-
buf the buffer
string the string to add
◆ xmlBufferWriteQuotedString()
void xmlBufferWriteQuotedString
(
xmlBuffer *
buf,
Append a quoted string to a buffer.
Append a string quoted with single or double quotes. If the string contains both single and double quotes, double quotes are escaped with ".
- Parameters
-
buf the buffer
string the string to add
◆ xmlBufGetNodeContent()
int xmlBufGetNodeContent
(
xmlBuf *
buf,
Append the string value of a node to buf.
For text nodes, the string value is the text content. Otherwise, the string value is the concatenation of the string values of the node's descendants.
Entity references are substituted.
- Parameters
-
cur the node being read
- Returns
- 0 in case of success and -1 in case of error.
◆ xmlBufNodeDump()
size_t xmlBufNodeDump
(
xmlBuf *
buf,
int level,
int format )
Serialize an XML node to an xmlBuf.
Uses the document's encoding. If the document has no encoding, uses ASCII without an encoding declaration.
Note that format only works if the document was parsed with XML_PARSE_NOBLANKS.
- Parameters
-
buf the XML buffer output
doc the document
cur the current node
level the imbrication level for indenting
format is formatting allowed
- Returns
- the number of bytes written to the buffer, in case of error 0 is returned or buf stores the error
◆ xmlBufShrink()
size_t xmlBufShrink
(
xmlBuf *
buf,
size_t len )
Discard bytes at the start of a buffer.
NOTE that the return value differs from xmlBufferShrink as it will return 0 on error instead of -1 due to size_t being used as the return type.
- Deprecated
- Internal function, don't use.
- Parameters
-
buf the buffer
len the number of bytes to remove
- Returns
- the number of bytes removed or 0 in case of failure
◆ xmlBufUse()
size_t xmlBufUse
(
xmlBuf *
buf )
Return the size of the buffer content.
- Parameters
-
buf the buffer
- Returns
- size of buffer content in bytes
◆ xmlBuildQName()
Build a QName from prefix and local name.
Builds the QName prefix:ncname in memory if there is enough space and prefix is not NULL nor empty, otherwise allocate a new string. If prefix is NULL or empty it returns ncname.
- Parameters
-
ncname the Name
prefix the prefix
memory preallocated memory
len preallocated memory length
- Returns
- the new string which must be freed by the caller if different from memory and ncname or NULL in case of error
◆ xmlChildElementCount()
unsigned long xmlChildElementCount
(
xmlNode *
parent )
Count the number of child nodes which are elements.
Note that entity references are not expanded.
- Parameters
-
parent the parent node
- Returns
- the number of element children or 0 if arguments are invalid.
◆ xmlCopyDoc()
Copy a document.
If recursive, the content tree will be copied too as well as DTD, namespaces and entities.
- Parameters
-
doc the document
recursive if not zero do a recursive copy.
- Returns
- the copied document or NULL if a memory allocation failed.
◆ xmlCopyDtd()
Copy a DTD.
- Parameters
-
dtd the DTD
- Returns
- the copied DTD or NULL if a memory allocation failed.
◆ xmlCopyNamespace()
Copy a namespace.
- Parameters
-
cur the namespace
- Returns
- the copied namespace or NULL if a memory allocation failed.
◆ xmlCopyNamespaceList()
Copy a namespace list.
- Parameters
-
cur the first namespace
- Returns
- the head of the copied list or NULL if a memory allocation failed.
◆ xmlCopyNode()
Copy a node.
If extended is 0, make a shallow copy.
If extended is 1, make a deep copy (properties, namespaces and children when applicable).
If extended is 2, make a shallow copy including properties and namespaces of elements.
Use of this function is DISCOURAGED in favor of xmlDocCopyNode.
- Parameters
-
node the node
extended mode of operation
- Returns
- the copied node or NULL if a memory allocation failed.
◆ xmlCopyNodeList()
Copy a node list and all children.
Use of this function is DISCOURAGED in favor of xmlDocCopyNodeList.
- Parameters
-
node the first node in the list.
- Returns
- the head of the copied list or NULL if a memory allocation failed.
◆ xmlCopyProp()
Create a copy of the attribute.
This function sets the parent pointer of the copy to target but doesn't set the attribute on the target element. Users should consider to set the attribute by calling xmlAddChild afterwards or reset the parent pointer to NULL.
- Parameters
-
target the element where the attribute will be grafted
cur the attribute
- Returns
- the copied attribute or NULL if a memory allocation failed.
◆ xmlCopyPropList()
Create a copy of an attribute list.
This function sets the parent pointers of the copied attributes to target but doesn't set the attributes on the target element.
- Parameters
-
target the element where the attributes will be grafted
cur the first attribute
- Returns
- the head of the copied list or NULL if a memory allocation failed.
◆ xmlCreateIntSubset()
Create a DTD node.
If a document is provided and it already has an internal subset, the existing DTD object is returned without creating a new object. If the document has no internal subset, it will be set to the created DTD.
- Parameters
-
doc the document pointer (optional)
name the DTD name (optional)
publicId public identifier of the DTD (optional)
systemId system identifier (URL) of the DTD (optional)
- Returns
- a pointer to the new or existing DTD object or NULL if arguments are invalid or a memory allocation failed.
◆ xmlDeregisterNodeDefault()
Registers a callback for node destruction.
- Deprecated
- don't use
- Parameters
-
func function pointer to the new DeregisterNodeFunc
- Returns
- the previous value of the deregistration function
◆ xmlDocCopyNode()
Copy a node into another document.
If extended is 0, make a shallow copy.
If extended is 1, make a deep copy (properties, namespaces and children when applicable).
If extended is 2, make a shallow copy including properties and namespaces of elements.
- Parameters
-
node the node
doc the document
extended mode of operation
- Returns
- the copied node or NULL if a memory allocation failed.
◆ xmlDocCopyNodeList()
Copy a node list and all children into a new document.
- Parameters
-
doc the target document
node the first node in the list.
- Returns
- the head of the copied list or NULL if a memory allocation failed.
◆ xmlDocDump()
int xmlDocDump
(
FILE * f,
Serialize an XML document to a FILE.
Uses the document's encoding. If the document has no encoding, uses ASCII without an encoding declaration.
- Parameters
-
f the FILE*
cur the document
- Returns
- the number of bytes written or -1 in case of failure.
◆ xmlDocDumpFormatMemory()
void xmlDocDumpFormatMemory
(
xmlDoc *
cur,
int * size,
int format )
Same as xmlDocDumpFormatMemoryEnc with encoding set to NULL.
- Parameters
-
cur the document
mem OUT: the memory pointer
size OUT: the memory length
format should formatting spaces been added
◆ xmlDocDumpFormatMemoryEnc()
void xmlDocDumpFormatMemoryEnc
(
xmlDoc *
out_doc,
int * doc_txt_len,
const char * txt_encoding,
int format )
Serialize an XML document to memory.
If encoding is NULL, uses the document's encoding. If the document has no encoding, serializes as ASCII without an encoding declaration.
It is up to the caller of this function to free the returned memory with xmlFree.
Note that format only works if the document was parsed with XML_PARSE_NOBLANKS.
- Parameters
-
out_doc Document to generate XML text from
doc_txt_ptr Memory pointer for allocated XML text
doc_txt_len Length of the generated XML text
txt_encoding Character encoding to use when generating XML text
format should formatting spaces been added
◆ xmlDocDumpMemory()
void xmlDocDumpMemory
(
xmlDoc *
cur,
int * size )
Same as xmlDocDumpFormatMemoryEnc with encoding set to NULL and format set to 0.
- Parameters
-
cur the document
mem OUT: the memory pointer
size OUT: the memory length
◆ xmlDocDumpMemoryEnc()
void xmlDocDumpMemoryEnc
(
xmlDoc *
out_doc,
int * doc_txt_len,
const char * txt_encoding )
Same as xmlDocDumpFormatMemoryEnc with format set to 0.
- Parameters
-
out_doc Document to generate XML text from
doc_txt_ptr Memory pointer for allocated XML text
doc_txt_len Length of the generated XML text
txt_encoding Character encoding to use when generating XML text
◆ xmlDocFormatDump()
int xmlDocFormatDump
(
FILE * f,
int format )
Serialize an XML document to a FILE.
Uses the document's encoding. If the document has no encoding, uses ASCII without an encoding declaration.
Note that format only works if the document was parsed with XML_PARSE_NOBLANKS.
- Parameters
-
f the FILE*
cur the document
format should formatting spaces been added
- Returns
- the number of bytes written or -1 in case of failure.
◆ xmlDocGetRootElement()
Get the root element of the document.
Searches the document's children for the root element. The first child is not necessarily the root element, but could also be a DTD, comment or PI.
- Parameters
-
doc the document
- Returns
- the root element or NULL if no element was found.
◆ xmlDocSetRootElement()
If root is NULL no action is taken.
To remove a node from a document, use xmlUnlinkNode instead.
Set the root element of the document (doc->children is a list containing possibly comments, PIs, etc ...).
root must be an element node. It is unlinked before insertion.
- Parameters
-
doc the document
root the new document root element
- Returns
- the unlinked old root element or NULL if the document didn't have a root element or a memory allocation failed.
◆ xmlDOMWrapAdoptNode()
Fix up namespaces before moving a node.
References of out-of scope ns-decls are remapped to point to destDoc: If destParent is given, then nsDef entries on element-nodes are used. If no destParent is given, then destDoc->oldNs entries are used This is the case when you have an unlinked node and just want to move it to the context of.
If destParent is given, it ensures that the tree is namespace wellformed by creating additional ns-decls where needed. Note that, since prefixes of already existent ns-decls can be shadowed by this process, it could break QNames in attribute values or element content.
NOTE: This function was not intensively tested.
- Parameters
-
ctxt the optional context for custom processing
sourceDoc the optional sourceDoc
node the node to start with
destDoc the destination doc
destParent the optional new parent of node in destDoc
options option flags
- Returns
- 0 if the operation succeeded, 1 if a node of unsupported type was given, 2 if a node of not yet supported type was given and -1 on API/internal errors.
◆ xmlDOMWrapCloneNode()
Clone a node and fix namespaces.
References of out-of scope ns-decls are remapped to point to destDoc. If destParent is given, then nsDef entries on element-nodes are used. If no destParent is given, then destDoc->oldNs entries are used. This is the case when you don't know already where the cloned branch will be added to.
If destParent is given, it ensures that the tree is namespace wellformed by creating additional ns-decls where needed. Note that, since prefixes of already existent ns-decls can be shadowed by this process, it could break QNames in attribute values or element content.
- Parameters
-
ctxt the optional context for custom processing
sourceDoc the optional sourceDoc
node the node to start with
resNode the clone of the given node
destDoc the destination doc
destParent the optional new parent of node in destDoc
deep descend into child if set
options option flags
- Returns
- 0 if the operation succeeded, 1 if a node of unsupported (or not yet supported) type was given, -1 on API/internal errors.
◆ xmlDOMWrapFreeCtxt()
Frees the DOM-wrapper context.
- Parameters
-
ctxt the DOM-wrapper context
◆ xmlDOMWrapNewCtxt()
Allocates and initializes a new DOM-wrapper context.
- Returns
- the xmlDOMWrapCtxt or NULL in case of an internal error.
◆ xmlDOMWrapReconcileNamespaces()
Fix up namespaces.
Ensures that ns-references point to ns-decls hold on element-nodes. Ensures that the tree is namespace wellformed by creating additional ns-decls where needed. Note that, since prefixes of already existent ns-decls can be shadowed by this process, it could break QNames in attribute values or element content.
NOTE: This function was not intensively tested.
- Parameters
-
ctxt DOM wrapper context, unused at the moment
elem the element-node
options option flags
- Returns
- 0 if succeeded, -1 otherwise and on API/internal errors.
◆ xmlDOMWrapRemoveNode()
Unlinks the given node from its owner.
This will substitute ns-references to node->nsDef for ns-references to doc->oldNs, thus ensuring the removed branch to be autark wrt ns-references.
NOTE: This function was not intensively tested.
- Parameters
-
ctxt a DOM wrapper context
doc the doc
node the node to be removed.
options set of options, unused at the moment
- Returns
- 0 on success, 1 if the node is not supported, -1 on API and internal errors.
◆ xmlElemDump()
void xmlElemDump
(
FILE * f,
Serialize an XML node to a FILE.
Uses the document's encoding. If the document has no encoding, uses ASCII without an encoding declaration.
- Parameters
-
f the FILE * for the output
doc the document
cur the current node
◆ xmlFirstElementChild()
Find the first child node which is an element.
Note that entity references are not expanded.
- Parameters
-
parent the parent node
- Returns
- the first element or NULL if parent has no children.
◆ xmlFreeDoc()
void xmlFreeDoc
(
xmlDoc *
cur )
Free a document including all children and associated DTDs.
- Parameters
-
cur pointer to the document
◆ xmlFreeDtd()
void xmlFreeDtd
(
xmlDtd *
cur )
Free a DTD structure.
- Parameters
-
cur the DTD structure to free up
◆ xmlFreeNode()
Free a node including all the children.
This doesn't unlink the node from the tree. Call xmlUnlinkNode first unless cur is a root node.
- Parameters
-
cur the node
◆ xmlFreeNodeList()
void xmlFreeNodeList
(
xmlNode *
cur )
Free a node list including all children.
- Parameters
-
cur the first node in the list
◆ xmlFreeNs()
void xmlFreeNs
(
xmlNs *
cur )
Free an xmlNs object.
- Parameters
-
cur the namespace pointer
◆ xmlFreeNsList()
void xmlFreeNsList
(
xmlNs *
cur )
Free a list of xmlNs objects.
- Parameters
-
cur the first namespace pointer
◆ xmlFreeProp()
Free an attribute including all children.
- Parameters
-
cur an attribute
◆ xmlFreePropList()
void xmlFreePropList
(
xmlAttr *
cur )
Free an attribute list including all children.
- Parameters
-
cur the first attribute in the list
◆ xmlGetBufferAllocationScheme()
Get the buffer allocation scheme.
- Deprecated
- Allocation schemes were removed.
- Returns
- the current allocation scheme
◆ xmlGetCompressMode()
int xmlGetCompressMode
(
void )
◆ xmlGetDocCompressMode()
int xmlGetDocCompressMode
(
const
xmlDoc *
doc )
Get the compression level of a document, ZLIB based.
- Parameters
-
doc the document
- Returns
- 0 (uncompressed) to 9 (max compression)
◆ xmlGetIntSubset()
Get the internal subset of a document.
- Parameters
-
doc the document pointer
- Returns
- a pointer to the DTD object or NULL if not found.
◆ xmlGetLastChild()
Find the last child of a node.
- Parameters
-
parent the parent node
- Returns
- the last child or NULL if parent has no children.
◆ xmlGetLineNo()
long xmlGetLineNo
(
const
xmlNode *
node )
Get line number of node.
Try to work around the limitation of line numbers being stored as 16 bits ints. Requires xmlParserOption XML_PARSE_BIG_LINES to be set when parsing.
- Parameters
-
node valid node
- Returns
- the line number if successful, -1 otherwise
◆ xmlGetNodePath()
Build a structure based Path for the given node.
- Parameters
-
node a node
- Returns
- the new path or NULL in case of error. The caller must free the returned string
◆ xmlGetNoNsProp()
Look up the value of an element's attribute.
Entities are substituted. The returned value must be freed by the caller.
This function looks in DTD attribute declarations for #FIXED or default declaration values.
This function is similar to xmlGetProp except it will accept only an attribute in no namespace.
NOTE: This function doesn't allow to distinguish malloc failures from missing attributes. It's more robust to use xmlNodeGetAttrValue.
- Parameters
-
node the element
name the attribute name
- Returns
- the attribute value or NULL if not found or a memory allocation failed.
◆ xmlGetNsList()
Find all in-scope namespaces of a node.
Use xmlGetNsListSafe for better error reporting.
- Parameters
-
doc the document
node the current node
- Returns
- a NULL terminated array of namespace pointers that must be freed by the caller or NULL if no namespaces were found or a memory allocation failed.
◆ xmlGetNsListSafe()
int xmlGetNsListSafe
(
const
xmlDoc *
doc,
Find all in-scope namespaces of a node.
out returns a NULL terminated array of namespace pointers that must be freed by the caller.
- Since
- 2.13.0
- Parameters
-
doc the document
node the current node
out the returned namespace array
- Returns
- 0 on success, 1 if no namespaces were found, -1 if a memory allocation failed.
◆ xmlGetNsProp()
Look up the value of an element's attribute.
The attribute has to match the specified namespace. A namespace of NULL means that the attribute must have no namespace.
Entities are substituted. The returned value must be freed by the caller.
This function looks in DTD attribute declaration for #FIXED or default declaration values.
NOTE: This function doesn't allow to distinguish malloc failures from missing attributes. It's more robust to use xmlNodeGetAttrValue.
- Parameters
-
node the element
name the attribute name
nameSpace the URI of the namespace
- Returns
- the attribute value or NULL if not found or a memory allocation failed.
◆ xmlGetProp()
Look up the value of an element's attribute.
Entities are substituted. The returned value must be freed by the caller.
This function looks in DTD attribute declarations for #FIXED or default declaration values.
NOTE: This function is ignores namespaces. Use xmlGetNsProp or xmlGetNoNsProp for namespace aware processing.
NOTE: This function doesn't allow to distinguish malloc failures from missing attributes.
- Parameters
-
node the element
name the attribute name
- Returns
- the attribute value or NULL if not found or a memory allocation failed.
◆ xmlHasNsProp()
Search for an attribute of an element.
The attribute has to match the specified namespace. A namespace of NULL means that the attribute must have no namespace.
This function also looks in DTD attribute declaration for #FIXED or default declaration values.
- Parameters
-
node the element
name the attribute name
nameSpace the URI of the namespace
- Returns
- the attribute or the attribute declaration or NULL if neither was found. Also returns NULL if a memory allocation failed making this function unreliable.
◆ xmlHasProp()
Search for an attribute of an element.
This function also looks in DTD attribute declaration for #FIXED or default declaration values.
- Parameters
-
node the element
name the attribute name
- Returns
- the attribute or the attribute declaration or NULL if neither was found. Also returns NULL if a memory allocation failed, making this function unreliable.
◆ xmlIsBlankNode()
int xmlIsBlankNode
(
const
xmlNode *
node )
Checks whether this node is an empty or whitespace-only text node.
- Parameters
-
node the node
- Returns
- 1 if yes, 0 if no
◆ xmlIsXHTML()
int xmlIsXHTML
(
const
xmlChar *
systemID,
Try to find if the document correspond to an XHTML DTD.
- Parameters
-
systemID the system identifier
publicID the public identifier
- Returns
- 1 if true, 0 if not and -1 in case of error
◆ xmlLastElementChild()
Find the last child node which is an element.
Note that entity references are not expanded.
- Parameters
-
parent the parent node
- Returns
- the last element or NULL if parent has no children.
◆ xmlNewCDataBlock()
Create a CDATA section node.
- Parameters
-
doc the target document (optional)
content raw text content (optional)
len size of text content
- Returns
- a pointer to the new node object or NULL if a memory allocation failed.
◆ xmlNewCharRef()
Create an empty entity reference node.
This function is MISNAMED. It doesn't create a character reference but an entity reference.
This function doesn't attempt to look up the entity in doc.
Entity names like &entity; are handled as well.
- Parameters
-
doc the target document (optional)
name the entity name
- Returns
- a pointer to the new node object or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNewChild()
Create a new child element and append it to a parent element.
If ns is NULL, the newly created element inherits the namespace of the parent.
If provided, content is expected to be a valid XML attribute value possibly containing character and entity references. Text and entity reference node will be added to the child element, see xmlNewDocNode.
- Parameters
-
parent the parent node
ns a namespace (optional)
name the name of the child
content text content with XML references (optional)
- Returns
- a pointer to the new node object or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNewComment()
Use of this function is DISCOURAGED in favor of xmlNewDocComment.
Create a comment node.
- Parameters
-
content the comment content (optional)
- Returns
- a pointer to the new node object or NULL if a memory allocation failed.
◆ xmlNewDoc()
Creates a new XML document.
If version is NULL, "1.0" is used.
- Parameters
-
version XML version string like "1.0" (optional)
- Returns
- a new document or NULL if a memory allocation failed.
◆ xmlNewDocComment()
Create a comment node.
- Parameters
-
doc the document
content the comment content
- Returns
- a pointer to the new node object or NULL if a memory allocation failed.
◆ xmlNewDocFragment()
Create a document fragment node.
- Parameters
-
doc the target document (optional)
- Returns
- a pointer to the new node object or NULL if a memory allocation failed.
◆ xmlNewDocNode()
Create an element node.
If provided, content is expected to be a valid XML attribute value possibly containing character and entity references. Syntax errors and references to undeclared entities are ignored silently. Only references are handled, nested elements, comments or PIs are not. See xmlNewDocRawNode for an alternative.
General notes on object creation:
Each node and all its children are associated with the same document. The document should be provided when creating nodes to avoid a performance penalty when adding the node to a document tree. Note that a document only owns nodes reachable from the root node. Unlinked subtrees must be freed manually.
- Parameters
-
doc the target document
ns namespace (optional)
name the node name
content text content with XML references (optional)
- Returns
- a pointer to the new node object or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNewDocNodeEatName()
Create an element node.
Like xmlNewDocNode, but the name string will be used directly without making a copy. Takes ownership of name which will also be freed on error.
- Parameters
-
doc the target document
ns namespace (optional)
name the node name
content text content with XML references (optional)
- Returns
- a pointer to the new node object or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNewDocPI()
Create a processing instruction object.
- Parameters
-
doc the target document (optional)
name the processing instruction target
content the PI content (optional)
- Returns
- a pointer to the new node object or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNewDocProp()
Create an attribute node.
If provided, value is expected to be a valid XML attribute value possibly containing character and entity references. Syntax errors and references to undeclared entities are ignored silently. If you want to pass a raw string, see xmlNewProp.
- Parameters
-
doc the target document (optional)
name the name of the attribute
value attribute value with XML references (optional)
- Returns
- a pointer to the attribute or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNewDocRawNode()
Create an element node.
If provided, value should be a raw, unescaped string.
- Parameters
-
doc the target document
ns namespace (optional)
name the node name
content raw text content (optional)
- Returns
- a pointer to the new node object or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNewDocText()
Create a new text node.
- Parameters
-
doc the target document
content raw text content (optional)
- Returns
- a pointer to the new node object or NULL if a memory allocation failed.
◆ xmlNewDocTextLen()
Create a new text node.
- Parameters
-
doc the target document
content raw text content (optional)
len size of text content
- Returns
- a pointer to the new node object or NULL if a memory allocation failed.
◆ xmlNewDtd()
Create a DTD node.
If a document is provided, it is an error if it already has an external subset. If the document has no external subset, it will be set to the created DTD.
To create an internal subset, use xmlCreateIntSubset.
- Parameters
-
doc the document pointer (optional)
name the DTD name (optional)
publicId public identifier of the DTD (optional)
systemId system identifier (URL) of the DTD (optional)
- Returns
- a pointer to the new DTD object or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNewNode()
Create an element node.
Use of this function is DISCOURAGED in favor of xmlNewDocNode.
- Parameters
-
ns namespace (optional)
name the node name
- Returns
- a pointer to the new node object or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNewNodeEatName()
Create an element node.
Use of this function is DISCOURAGED in favor of xmlNewDocNodeEatName.
Like xmlNewNode, but the name string will be used directly without making a copy. Takes ownership of name which will also be freed on error.
- Parameters
-
ns namespace (optional)
name the node name
- Returns
- a pointer to the new node object or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNewNs()
Create a new namespace.
For a default namespace, prefix should be NULL. The namespace URI in href is not checked. You should make sure to pass a valid URI.
If node is provided, it must be an element node. The namespace will be appended to the node's namespace declarations. It is an error if the node already has a definition for the prefix or default namespace.
- Parameters
-
node the element carrying the namespace (optional)
href the URI associated
prefix the prefix for the namespace (optional)
- Returns
- a new namespace pointer or NULL if arguments are invalid, the prefix is already in use or a memory allocation failed.
◆ xmlNewNsProp()
Create an attribute node.
If provided, value should be a raw, unescaped string.
If node is provided, the created attribute will be appended without checking for duplicate names. It is an error if node is not an element.
- Parameters
-
node the parent node (optional)
ns the namespace (optional)
name the local name of the attribute
value the value of the attribute (optional)
- Returns
- a pointer to the attribute or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNewNsPropEatName()
Create an attribute node.
Like xmlNewNsProp, but the name string will be used directly without making a copy. Takes ownership of name which will also be freed on error.
- Parameters
-
node the parent node (optional)
ns the namespace (optional)
name the local name of the attribute
value the value of the attribute (optional)
- Returns
- a pointer to the attribute or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNewPI()
Create a processing instruction node.
Use of this function is DISCOURAGED in favor of xmlNewDocPI.
- Parameters
-
name the processing instruction target
content the PI content (optional)
- Returns
- a pointer to the new node object or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNewProp()
Create an attribute node.
If provided, value should be a raw, unescaped string.
If node is provided, the created attribute will be appended without checking for duplicate names. It is an error if node is not an element.
- Parameters
-
node the parent node (optional)
name the name of the attribute
value the value of the attribute (optional)
- Returns
- a pointer to the attribute or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNewReference()
Create a new entity reference node, linking the result with the entity in doc if found.
Entity names like &entity; are handled as well.
- Parameters
-
doc the target document (optional)
name the entity name
- Returns
- a pointer to the new node object or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNewText()
Create a text node.
Use of this function is DISCOURAGED in favor of xmlNewDocText.
- Parameters
-
content raw text content (optional)
- Returns
- a pointer to the new node object or NULL if a memory allocation failed.
◆ xmlNewTextChild()
Create a new child element and append it to a parent element.
If ns is NULL, the newly created element inherits the namespace of the parent.
If content is provided, a text node will be added to the child element, see xmlNewDocRawNode.
- Parameters
-
parent the parent node
ns a namespace (optional)
name the name of the child
content raw text content of the child (optional)
- Returns
- a pointer to the new node object or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNewTextLen()
Create a new text node.
Use of this function is DISCOURAGED in favor of xmlNewDocTextLen.
- Parameters
-
content raw text content (optional)
len size of text content
- Returns
- a pointer to the new node object or NULL if a memory allocation failed.
◆ xmlNextElementSibling()
Find the closest following sibling which is a element.
Note that entity references are not expanded.
- Parameters
-
node the current node
- Returns
- the sibling or NULL if no sibling was found.
◆ xmlNodeAddContent()
int xmlNodeAddContent
(
xmlNode *
cur,
Append the extra substring to the node content.
NOTE: In contrast to xmlNodeSetContent, content is supposed to be raw text, so unescaped XML special chars are allowed, entity references are not supported.
This doesn't work on attributes before version 2.15.
- Parameters
-
cur the node being modified
content extra content
- Returns
- 0 on success, 1 on error, -1 if a memory allocation failed.
◆ xmlNodeAddContentLen()
int xmlNodeAddContentLen
(
xmlNode *
cur,
int len )
Append the extra substring to the node content.
NOTE: In contrast to xmlNodeSetContentLen, content is supposed to be raw text, so unescaped XML special chars are allowed, entity references are not supported.
This doesn't work on attributes before version 2.15.
- Parameters
-
cur the node being modified
content extra content
len the size of content
- Returns
- 0 on success, 1 on error, -1 if a memory allocation failed.
◆ xmlNodeBufGetContent()
int xmlNodeBufGetContent
(
xmlBuffer *
buffer,
Append the string value of a node to buffer.
For text nodes, the string value is the text content. Otherwise, the string value is the concatenation of the string values of the node's descendants.
Entity references are substituted.
- Parameters
-
buffer a buffer
cur the node being read
- Returns
- 0 in case of success and -1 in case of error.
◆ xmlNodeDump()
Serialize an XML node to an xmlBuffer.
Uses the document's encoding. If the document has no encoding, uses ASCII without an encoding declaration.
Note that format only works if the document was parsed with XML_PARSE_NOBLANKS.
Since this is using xmlBuffer structures it is limited to 2GB and somewhat deprecated, use xmlNodeDumpOutput instead.
- Parameters
-
buf the XML buffer output
doc the document
cur the current node
level the initial indenting level
format is formatting allowed
- Returns
- the number of bytes written to the buffer or -1 in case of error
◆ xmlNodeDumpOutput()
int level,
int format,
const char * encoding )
Serialize an XML node to an output buffer.
If encoding is NULL, uses the document's encoding. If the document has no encoding, serializes as ASCII without an encoding declaration.
Note that format only works if the document was parsed with XML_PARSE_NOBLANKS.
- Parameters
-
buf the XML buffer output
doc the document
cur the current node
level the imbrication level for indenting
format is formatting allowed
encoding an optional encoding string
◆ xmlNodeGetAttrValue()
int xmlNodeGetAttrValue
(
const
xmlNode *
node,
Look up the value of an element's attribute.
The attribute has to match the specified namespace. A namespace of NULL means that the attribute must have no namespace.
Entities are substituted. The returned value must be freed by the caller.
- Since
- 2.13.0
- Parameters
-
node the element
name the attribute name
nsUri the URI of the namespace
out the returned string
- Returns
- 0 on success, 1 if no attribute was found, -1 if a memory allocation failed.
◆ xmlNodeGetBase()
See xmlNodeGetBaseSafe.
This function doesn't allow to distinguish memory allocation failures from a non-existing base.
- Parameters
-
doc the document the node pertains to
cur the node being checked
- Returns
- a pointer to the base URL, or NULL if not found It's up to the caller to free the memory with xmlFree.
◆ xmlNodeGetBaseSafe()
int xmlNodeGetBaseSafe
(
const
xmlDoc *
doc,
Searches for the base URI.
The code should work on both XML and HTML document even if base mechanisms are completely different. It returns the base as defined in RFC 2396 sections "5.1.1. Base
URI within Document Content" and "5.1.2. Base URI from the
Encapsulating Entity". However it does not return the document base (5.1.3), use doc->URL in this case.
- Since
- 2.13.0
- Parameters
-
doc the document the node pertains to
cur the node being checked
baseOut pointer to base
- Returns
- 0 in case of success, 1 if a URI or argument is invalid, -1 if a memory allocation failed.
◆ xmlNodeGetContent()
Returns the string value of a node.
For text nodes, the string value is the text content. Otherwise, the string value is the concatenation of the string values of the node's descendants.
Entity references are substituted.
It's up to the caller to free the result with xmlFree.
- Parameters
-
cur the node being read
- Returns
- a new string or NULL if arguments are invalid or a memory allocation failed.
◆ xmlNodeGetLang()
Find the xml:lang of a node.
Look up the value of the xml:lang attribute or the one carried by the nearest ancestor.
- Parameters
-
cur the node being checked
- Returns
- a pointer to the lang value, or NULL if not found It's up to the caller to free the memory with xmlFree.
◆ xmlNodeGetSpacePreserve()
int xmlNodeGetSpacePreserve
(
const
xmlNode *
cur )
Find the xml:space of a node.
Look up the value of the xml:space attribute or the one carried by the nearest ancestor.
- Parameters
-
cur the node being checked
- Returns
- -1 if xml:space is not inherited, 0 if "default", 1 if "preserve"
◆ xmlNodeIsText()
int xmlNodeIsText
(
const
xmlNode *
node )
Check whether the node is a text node.
- Parameters
-
node the node
- Returns
- 1 if yes, 0 if no
◆ xmlNodeListGetRawString()
Serializes attribute children (text and entity reference nodes) into a string.
If inLine is true, entity references will be substituted. Otherwise, entity references will be kept and special characters like & will be escaped. See xmlEncodeSpecialChars for details.
- Parameters
-
doc a document (unused)
list a node list of attribute children
inLine whether entity references are substituted
- Returns
- a string or NULL if a memory allocation failed.
◆ xmlNodeListGetString()
Serializes attribute children (text and entity reference nodes) into a string.
If inLine is true, entity references will be substituted. Otherwise, entity references will be kept and special characters like & as well as non-ASCII chars will be escaped. See xmlEncodeEntitiesReentrant for details. If list is the child of an attribute, escaping rules apply are adjusted.
See xmlNodeListGetRawString for an alternative option.
- Parameters
-
doc a document (optional)
list a node list of attribute children
inLine whether entity references are substituted
- Returns
- a string or NULL if a memory allocation failed.
◆ xmlNodeSetBase()
int xmlNodeSetBase
(
xmlNode *
cur,
Set (or reset) the base URI of a node, i.e.
the value of the xml:base attribute.
- Parameters
-
cur the node being changed
uri the new base URI
- Returns
- 0 on success, -1 on error.
◆ xmlNodeSetContent()
int xmlNodeSetContent
(
xmlNode *
cur,
Replace the text content of a node.
Sets the raw text content of text, CDATA, comment or PI nodes.
For element and attribute nodes, removes all children and replaces them by parsing content which is expected to be a valid XML attribute value possibly containing character and entity references. Syntax errors and references to undeclared entities are ignored silently. Unfortunately, there isn't an API to pass raw content directly. An inefficient work-around is to escape the content with xmlEncodeSpecialChars before passing it. A better trick is clearing the old content with xmlNodeSetContent(node, NULL) first and then calling xmlNodeAddContent(node, content). Unlike this function, xmlNodeAddContent accepts raw text.
- Parameters
-
cur the node being modified
content the new value of the content
- Returns
- 0 on success, 1 on error, -1 if a memory allocation failed.
◆ xmlNodeSetContentLen()
int xmlNodeSetContentLen
(
xmlNode *
cur,
int len )
See xmlNodeSetContent.
- Parameters
-
cur the node being modified
content the new value of the content
len the size of content
- Returns
- 0 on success, 1 on error, -1 if a memory allocation failed.
◆ xmlNodeSetLang()
int xmlNodeSetLang
(
xmlNode *
cur,
Set the xml:lang attribute of a node.
- Parameters
-
cur the node being changed
lang the language description
- Returns
- 0 on success, 1 if arguments are invalid, -1 if a memory allocation failed.
◆ xmlNodeSetName()
void xmlNodeSetName
(
xmlNode *
cur,
Set (or reset) the name of a node.
- Parameters
-
cur the node being changed
name the new tag name
◆ xmlNodeSetSpacePreserve()
int xmlNodeSetSpacePreserve
(
xmlNode *
cur,
int val )
Set the xml:space attribute of a node.
- Parameters
-
cur the node being changed
val the xml:space value ("0": default, 1: "preserve")
- Returns
- 0 on success, 1 if arguments are invalid, -1 if a memory allocation failed.
◆ xmlPreviousElementSibling()
Find the closest preceding sibling which is a element.
Note that entity references are not expanded.
- Parameters
-
node the current node
- Returns
- the sibling or NULL if no sibling was found.
◆ xmlReconciliateNs()
int xmlReconciliateNs
(
xmlDoc *
doc,
This function checks that all the namespaces declared within the given tree are properly declared.
This is needed for example after copy or cut and then paste operations. The subtree may still hold pointers to namespace declarations outside the subtree or invalid/masked. As much as possible the function tries to reuse the existing namespaces found in the new environment. If not possible the new namespaces are redeclared on tree at the top of the given subtree.
- Parameters
-
doc the document
tree a node defining the subtree to reconciliate
- Returns
- 0 on success or -1 in case of error.
◆ xmlRegisterNodeDefault()
Registers a callback for node creation.
- Deprecated
- don't use
- Parameters
-
func function pointer to the new RegisterNodeFunc
- Returns
- the old value of the registration function
◆ xmlRemoveProp()
int xmlRemoveProp
(
xmlAttr *
cur )
Unlink and free an attribute including all children.
Note this doesn't work for namespace declarations.
The attribute must have a non-NULL parent pointer.
- Parameters
-
cur an attribute
- Returns
- 0 on success or -1 if the attribute was not found or arguments are invalid.
◆ xmlReplaceNode()
Unlink the old node.
If cur is provided, it is unlinked and inserted in place of old.
It is an error if old has no parent.
Unlike xmlAddChild, this function doesn't merge text nodes or delete duplicate attributes.
See the notes in xmlAddChild.
- Parameters
-
old the old node
cur the node (optional)
- Returns
- old or NULL if arguments are invalid or a memory allocation failed.
◆ xmlSaveFile()
int xmlSaveFile
(
const char * filename,
Same as xmlSaveFormatFileEnc with encoding set to NULL and format set to 0.
- Parameters
-
filename the filename (or URL)
cur the document
- Returns
- the number of bytes written or -1 in case of failure.
◆ xmlSaveFileEnc()
int xmlSaveFileEnc
(
const char * filename,
const char * encoding )
Same as xmlSaveFormatFileEnc with format set to 0.
- Parameters
-
filename the filename (or URL)
cur the document
encoding the name of an encoding (or NULL)
- Returns
- the number of bytes written or -1 in case of failure.
◆ xmlSaveFileTo()
Same as xmlSaveFormatFileTo with format set to 0.
WARNING: This calls xmlOutputBufferClose and frees buf.
- Parameters
-
buf an output I/O buffer
cur the document
encoding the encoding if any assuming the I/O layer handles the transcoding
- Returns
- the number of bytes written or -1 in case of failure.
◆ xmlSaveFormatFile()
int xmlSaveFormatFile
(
const char * filename,
int format )
Same as xmlSaveFormatFileEnc with encoding set to NULL.
- Parameters
-
filename the filename (or URL)
cur the document
format should formatting spaces been added
- Returns
- the number of bytes written or -1 in case of failure.
◆ xmlSaveFormatFileEnc()
int xmlSaveFormatFileEnc
(
const char * filename,
const char * encoding,
int format )
Serialize an XML document to a file using the given encoding.
If filename is "-", stdout is used. This is potentially insecure and might be changed in a future version.
If encoding is NULL, uses the document's encoding. If the document has no encoding, serializes as ASCII without an encoding declaration.
Note that format only works if the document was parsed with XML_PARSE_NOBLANKS.
- Parameters
-
filename the filename or URL to output
cur the document being saved
encoding the name of the encoding to use or NULL.
format should formatting spaces be added.
- Returns
- the number of bytes written or -1 in case of error.
◆ xmlSaveFormatFileTo()
const char * encoding,
int format )
Serialize an XML document to an output buffer.
If the output buffer already uses a (non-default) encoding, encoding is ignored. If the output buffer has no encoding and encoding is NULL, uses the document's encoding or ASCII without an encoding declaration.
Note that format only works if the document was parsed with XML_PARSE_NOBLANKS.
WARNING: This calls xmlOutputBufferClose and frees buf.
- Parameters
-
buf an output I/O buffer
cur the document
encoding the encoding if any assuming the I/O layer handles the transcoding
format should formatting spaces been added
- Returns
- the number of bytes written or -1 in case of failure.
◆ xmlSearchNs()
Search for a namespace with prefix in scope of node.
Recurse on the parents until it finds the defined namespace or return NULL otherwise.
If nameSpace is NULL, the default namespace is looked up.
Namespace search doesn't cross entity boundaries.
- Parameters
-
doc the document
node the current node
nameSpace the namespace prefix
- Returns
- the namespace pointer or NULL if no namespace was found or a memory allocation failed. Allocations can only fail if the xml namespace is queried.
◆ xmlSearchNsByHref()
Search for a namespace matching URI in scope of node.
- Parameters
-
doc the document
node the current node
href the namespace value
- Returns
- the namespace pointer or NULL if no namespace was found or a memory allocation failed. Allocations can only fail if the xml namespace is queried.
◆ xmlSetBufferAllocationScheme()
Set the buffer allocation scheme.
- Deprecated
- No-op, allocation schemes were removed.
- Parameters
-
scheme allocation method to use
◆ xmlSetCompressMode()
void xmlSetCompressMode
(
int mode )
Set the global compression level, ZLIB based.
- Deprecated
- Use xmlSetDocCompressMode
Correct values: 0 (uncompressed) to 9 (max compression)
- Parameters
-
mode the compression ratio
◆ xmlSetDocCompressMode()
void xmlSetDocCompressMode
(
xmlDoc *
doc,
int mode )
Set the compression level of a document, ZLIB based.
Correct values: 0 (uncompressed) to 9 (max compression)
- Parameters
-
doc the document
mode the compression ratio
◆ xmlSetListDoc()
int xmlSetListDoc
(
xmlNode *
list,
Associate all subtrees in list with a new document.
Internal function, see xmlSetTreeDoc.
- Parameters
-
list a node list
doc new document
- Returns
- 0 on success. If a memory allocation fails, returns -1. All subtrees will be updated on failure but some strings may be lost.
◆ xmlSetNs()
Set the namespace of an element or attribute node.
Passing a NULL namespace unsets the namespace.
- Parameters
-
node a node in the document
ns a namespace pointer (optional)
◆ xmlSetNsProp()
Set (or reset) an element's attribute.
The namespace must be in scope.
- Parameters
-
node the node
ns the namespace definition
name the attribute name
value the attribute value
- Returns
- the attribute pointer.
◆ xmlSetProp()
Set (or reset) an element's attribute.
If name has a prefix, the corresponding namespace will be used. It is an error if there's no such binding for the prefix in scope.
- Parameters
-
node the node
name the attribute name (a QName)
value the attribute value
- Returns
- the attribute pointer.
◆ xmlSetTreeDoc()
int xmlSetTreeDoc
(
xmlNode *
tree,
Associate all nodes in a tree with a new document.
This is an internal function which shouldn't be used. It is invoked by functions like xmlAddChild, xmlAddSibling or xmlReplaceNode. tree must be the root node of an unlinked subtree.
Also copy strings from the old document's dictionary and remove ID attributes from the old ID table.
- Parameters
-
tree root of a subtree
doc new document
- Returns
- 0 on success. If a memory allocation fails, returns -1. The whole tree will be updated on failure but some strings may be lost.
◆ xmlSplitQName2()
Parse an XML qualified name.
- Deprecated
- This function doesn't report malloc failures.
[NS 5] QName ::= (Prefix ':')? LocalPart
[NS 6] Prefix ::= NCName
[NS 7] LocalPart ::= NCName
- Parameters
-
name the full QName
- Returns
- NULL if the name doesn't have a prefix. Otherwise, returns the local part, and prefix is updated to get the Prefix. Both the return value and the prefix must be freed by the caller.
◆ xmlSplitQName3()
Parse an XML qualified name.
- Parameters
-
name the full QName
len an int *
- Returns
- NULL if it is not a Qualified Name, otherwise, update len with the length in byte of the prefix and return a pointer to the start of the name without the prefix
◆ xmlStringGetNodeList()
Parse an attribute value and build a node list with text and entity reference nodes.
The resulting nodes will be associated with the document if provided. The document is also used to look up entities.
- Deprecated
- Internal function, don't use.
The input is not validated. Syntax errors or references to undeclared entities will be ignored silently with unspecified results.
- Parameters
-
doc a document (optional)
value an attribute value
- Returns
- a pointer to the first child or NULL if the value if empty or a memory allocation failed.
◆ xmlStringLenGetNodeList()
See xmlStringGetNodeList.
- Deprecated
- Internal function, don't use.
- Parameters
-
doc a document (optional)
value an attribute value
len maximum length of the attribute value
- Returns
- a pointer to the first child or NULL if the value if empty or a memory allocation failed.
◆ xmlTextConcat()
int xmlTextConcat
(
xmlNode *
node,
int len )
Concat the given string at the end of the existing node content.
If len is -1, the string length will be calculated.
- Parameters
-
node the node
content the content
len content length
- Returns
- -1 in case of error, 0 otherwise
◆ xmlTextMerge()
Merge the second text node into the first.
If first is NULL, second is returned. Otherwise, the second node is unlinked and freed.
- Parameters
-
first the first text node
second the second text node being merged
- Returns
- the first text node augmented or NULL in case of error.
◆ xmlThrDefDeregisterNodeDefault()
Set per-thread default value.
- Deprecated
- This feature will be removed.
- Parameters
-
func new value
- Returns
- the old value
◆ xmlThrDefRegisterNodeDefault()
Set per-thread default value.
- Deprecated
- This feature will be removed.
- Parameters
-
func new value
- Returns
- the old value
◆ xmlUnlinkNode()
void xmlUnlinkNode
(
xmlNode *
cur )
Unlink a node from its tree.
The node is not freed. Unless it is reinserted, it must be managed manually and freed eventually by calling xmlFreeNode.
- Parameters
-
cur the node
◆ xmlUnsetNsProp()
int xmlUnsetNsProp
(
xmlNode *
node,
Remove an attribute of an element.
- Parameters
-
node the element
ns the namespace definition
name the attribute name
- Returns
- 0 if successful, -1 if not found
◆ xmlUnsetProp()
Remove an attribute of an element.
This handles only attributes in no namespace.
- Parameters
-
node the element
name the attribute name
- Returns
- 0 if successful, -1 if not found
◆ xmlValidateName()
int xmlValidateName
(
const
xmlChar *
value,
int space )
Check that a value conforms to the lexical space of Name.
- Parameters
-
value the value to check
space allow spaces in front and end of the string
- Returns
- 0 if this validates, a positive error code number otherwise and -1 in case of internal or API error.
◆ xmlValidateNCName()
int xmlValidateNCName
(
const
xmlChar *
value,
int space )
Check that a value conforms to the lexical space of NCName.
- Parameters
-
value the value to check
space allow spaces in front and end of the string
- Returns
- 0 if this validates, a positive error code number otherwise and -1 in case of internal or API error.
◆ xmlValidateNMToken()
int xmlValidateNMToken
(
const
xmlChar *
value,
int space )
Check that a value conforms to the lexical space of NMToken.
- Parameters
-
value the value to check
space allow spaces in front and end of the string
- Returns
- 0 if this validates, a positive error code number otherwise and -1 in case of internal or API error.
◆ xmlValidateQName()
int xmlValidateQName
(
const
xmlChar *
value,
int space )
Check that a value conforms to the lexical space of QName.
- Parameters
-
value the value to check
space allow spaces in front and end of the string
- Returns
- 0 if this validates, a positive error code number otherwise and -1 in case of internal or API error.