Doxygen/debugging.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@411 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
parent
2a4701328c
commit
23260a7df1
@ -1628,7 +1628,7 @@ EXPORT_SPEC void ixmlNodeList_free(
|
|||||||
* of the DOM tree or \c NULL on an error.
|
* of the DOM tree or \c NULL on an error.
|
||||||
*/
|
*/
|
||||||
EXPORT_SPEC DOMString ixmlPrintDocument(
|
EXPORT_SPEC DOMString ixmlPrintDocument(
|
||||||
/*! The document node to print. */
|
/*! [in] The document node to print. */
|
||||||
IXML_Document *doc);
|
IXML_Document *doc);
|
||||||
|
|
||||||
|
|
||||||
@ -1650,7 +1650,7 @@ EXPORT_SPEC DOMString ixmlPrintDocument(
|
|||||||
* \c NULL on an error.
|
* \c NULL on an error.
|
||||||
*/
|
*/
|
||||||
EXPORT_SPEC DOMString ixmlPrintNode(
|
EXPORT_SPEC DOMString ixmlPrintNode(
|
||||||
/*! The root of the \b Node tree to render to XML text. */
|
/*! [in] The root of the \b Node tree to render to XML text. */
|
||||||
IXML_Node *doc
|
IXML_Node *doc
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1674,7 +1674,7 @@ EXPORT_SPEC DOMString ixmlPrintNode(
|
|||||||
* \c NULL on an error.
|
* \c NULL on an error.
|
||||||
*/
|
*/
|
||||||
EXPORT_SPEC DOMString ixmlDocumenttoString(
|
EXPORT_SPEC DOMString ixmlDocumenttoString(
|
||||||
/*! The root of the \b Node tree to render to XML text. */
|
/*! [in] The root of the \b Node tree to render to XML text. */
|
||||||
IXML_Document *doc);
|
IXML_Document *doc);
|
||||||
|
|
||||||
|
|
||||||
@ -1693,7 +1693,7 @@ EXPORT_SPEC DOMString ixmlDocumenttoString(
|
|||||||
* \c NULL on an error.
|
* \c NULL on an error.
|
||||||
*/
|
*/
|
||||||
EXPORT_SPEC DOMString ixmlNodetoString(
|
EXPORT_SPEC DOMString ixmlNodetoString(
|
||||||
/*! The root of the \b Node tree to render to XML text. */
|
/*! [in] The root of the \b Node tree to render to XML text. */
|
||||||
IXML_Node *doc);
|
IXML_Node *doc);
|
||||||
|
|
||||||
|
|
||||||
@ -1701,7 +1701,7 @@ EXPORT_SPEC DOMString ixmlNodetoString(
|
|||||||
* \brief Makes the XML parser more tolerant to malformed text.
|
* \brief Makes the XML parser more tolerant to malformed text.
|
||||||
*/
|
*/
|
||||||
EXPORT_SPEC void ixmlRelaxParser(
|
EXPORT_SPEC void ixmlRelaxParser(
|
||||||
/*! If \b errorChar is 0 (default), the parser is strict about XML
|
/*! [in] If \b errorChar is 0 (default), the parser is strict about XML
|
||||||
* encoding : invalid UTF-8 sequences or "&" entities are rejected, and
|
* encoding : invalid UTF-8 sequences or "&" entities are rejected, and
|
||||||
* the parsing aborts.
|
* the parsing aborts.
|
||||||
*
|
*
|
||||||
@ -1718,7 +1718,7 @@ EXPORT_SPEC void ixmlRelaxParser(
|
|||||||
* \return A \b Document if the buffer correctly parses or \c NULL on an error.
|
* \return A \b Document if the buffer correctly parses or \c NULL on an error.
|
||||||
*/
|
*/
|
||||||
EXPORT_SPEC IXML_Document *ixmlParseBuffer(
|
EXPORT_SPEC IXML_Document *ixmlParseBuffer(
|
||||||
/*! The buffer that contains the XML text to convert to a \b Document. */
|
/*! [in] The buffer that contains the XML text to convert to a \b Document. */
|
||||||
const char *buffer);
|
const char *buffer);
|
||||||
|
|
||||||
|
|
||||||
@ -1737,9 +1737,9 @@ EXPORT_SPEC IXML_Document *ixmlParseBuffer(
|
|||||||
* to complete this operation.
|
* to complete this operation.
|
||||||
*/
|
*/
|
||||||
EXPORT_SPEC int ixmlParseBufferEx(
|
EXPORT_SPEC int ixmlParseBufferEx(
|
||||||
/*! The buffer that contains the XML text to convert to a \b Document. */
|
/*! [in] The buffer that contains the XML text to convert to a \b Document. */
|
||||||
const char *buffer,
|
const char *buffer,
|
||||||
/*! A point to store the \b Document if file correctly parses or \b NULL on an error. */
|
/*! [out] A point to store the \b Document if file correctly parses or \b NULL on an error. */
|
||||||
IXML_Document** doc);
|
IXML_Document** doc);
|
||||||
|
|
||||||
|
|
||||||
@ -1749,7 +1749,7 @@ EXPORT_SPEC int ixmlParseBufferEx(
|
|||||||
* \return A \b Document if the file correctly parses or \c NULL on an error.
|
* \return A \b Document if the file correctly parses or \c NULL on an error.
|
||||||
*/
|
*/
|
||||||
EXPORT_SPEC IXML_Document *ixmlLoadDocument(
|
EXPORT_SPEC IXML_Document *ixmlLoadDocument(
|
||||||
/*! The filename of the XML text to convert to a \b Document. */
|
/*! [in] The filename of the XML text to convert to a \b Document. */
|
||||||
const char* xmlFile);
|
const char* xmlFile);
|
||||||
|
|
||||||
|
|
||||||
@ -1768,9 +1768,9 @@ EXPORT_SPEC IXML_Document *ixmlLoadDocument(
|
|||||||
* to complete this operation.
|
* to complete this operation.
|
||||||
*/
|
*/
|
||||||
EXPORT_SPEC int ixmlLoadDocumentEx(
|
EXPORT_SPEC int ixmlLoadDocumentEx(
|
||||||
/*! The filename of the XML text to convert to a \b Document. */
|
/*! [in] The filename of the XML text to convert to a \b Document. */
|
||||||
const char *xmlFile,
|
const char *xmlFile,
|
||||||
/*! A pointer to the \b Document if file correctly parses or \b NULL
|
/*! [out] A pointer to the \b Document if file correctly parses or \b NULL
|
||||||
* on an error. */
|
* on an error. */
|
||||||
IXML_Document **doc);
|
IXML_Document **doc);
|
||||||
|
|
||||||
@ -1782,7 +1782,7 @@ EXPORT_SPEC int ixmlLoadDocumentEx(
|
|||||||
* if the operation could not be completed.
|
* if the operation could not be completed.
|
||||||
*/
|
*/
|
||||||
EXPORT_SPEC DOMString ixmlCloneDOMString(
|
EXPORT_SPEC DOMString ixmlCloneDOMString(
|
||||||
/*! The source \b DOMString to clone. */
|
/*! [in] The source \b DOMString to clone. */
|
||||||
const DOMString src);
|
const DOMString src);
|
||||||
|
|
||||||
|
|
||||||
@ -1790,7 +1790,7 @@ EXPORT_SPEC DOMString ixmlCloneDOMString(
|
|||||||
* \brief Frees a \b DOMString.
|
* \brief Frees a \b DOMString.
|
||||||
*/
|
*/
|
||||||
EXPORT_SPEC void ixmlFreeDOMString(
|
EXPORT_SPEC void ixmlFreeDOMString(
|
||||||
/*! The \b DOMString to free. */
|
/*! [in] The \b DOMString to free. */
|
||||||
DOMString buf);
|
DOMString buf);
|
||||||
|
|
||||||
|
|
||||||
|
806
ixml/src/ixml.c
806
ixml/src/ixml.c
@ -34,500 +34,426 @@
|
|||||||
#include "ixmlmembuf.h"
|
#include "ixmlmembuf.h"
|
||||||
#include "ixmlparser.h"
|
#include "ixmlparser.h"
|
||||||
|
|
||||||
/*================================================================
|
|
||||||
* copy_with_escape
|
/*!
|
||||||
*
|
* \file
|
||||||
*
|
*/
|
||||||
*=================================================================*/
|
|
||||||
static void
|
|
||||||
copy_with_escape( INOUT ixml_membuf * buf,
|
/*!
|
||||||
IN const char *p )
|
* \todo Documentation.
|
||||||
|
*/
|
||||||
|
static void copy_with_escape(
|
||||||
|
/*! [in,out] \todo documentation. */
|
||||||
|
INOUT ixml_membuf *buf,
|
||||||
|
/*! [in] \todo documentation. */
|
||||||
|
IN const char *p)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int plen;
|
int plen;
|
||||||
|
|
||||||
if( p == NULL )
|
if (p == NULL) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
plen = strlen( p );
|
plen = strlen( p );
|
||||||
|
|
||||||
for( i = 0; i < plen; i++ ) {
|
for (i = 0; i < plen; i++) {
|
||||||
switch ( p[i] ) {
|
switch (p[i]) {
|
||||||
case '<':
|
case '<':
|
||||||
ixml_membuf_append_str( buf, "<" );
|
ixml_membuf_append_str(buf, "<");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '>':
|
case '>':
|
||||||
ixml_membuf_append_str( buf, ">" );
|
ixml_membuf_append_str(buf, ">");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '&':
|
case '&':
|
||||||
ixml_membuf_append_str( buf, "&" );
|
ixml_membuf_append_str(buf, "&");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\'':
|
case '\'':
|
||||||
ixml_membuf_append_str( buf, "'" );
|
ixml_membuf_append_str(buf, "'");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\"':
|
case '\"':
|
||||||
ixml_membuf_append_str( buf, """ );
|
ixml_membuf_append_str(buf, """);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ixml_membuf_append( buf, &p[i] );
|
ixml_membuf_append(buf, &p[i]);
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*================================================================
|
/*!
|
||||||
* ixmlPrintDomTreeRecursive
|
* \brief Recursive function to print all the node in a tree.
|
||||||
* It is a recursive function to print all the node in a tree.
|
* Internal to parser only.
|
||||||
* Internal to parser only.
|
*/
|
||||||
*
|
static void ixmlPrintDomTreeRecursive(
|
||||||
*=================================================================*/
|
/*! [in] \todo documentation. */
|
||||||
void
|
IN IXML_Node *nodeptr,
|
||||||
ixmlPrintDomTreeRecursive( IN IXML_Node * nodeptr,
|
/*! [in] \todo documentation. */
|
||||||
IN ixml_membuf * buf )
|
IN ixml_membuf *buf)
|
||||||
{
|
{
|
||||||
const char *nodeName = NULL;
|
const char *nodeName = NULL;
|
||||||
const char *nodeValue = NULL;
|
const char *nodeValue = NULL;
|
||||||
IXML_Node *child = NULL,
|
IXML_Node *child = NULL,
|
||||||
*sibling = NULL;
|
*sibling = NULL;
|
||||||
|
|
||||||
if( nodeptr != NULL ) {
|
if (nodeptr != NULL) {
|
||||||
nodeName = ( const char * )ixmlNode_getNodeName( nodeptr );
|
nodeName = (const char *)ixmlNode_getNodeName(nodeptr);
|
||||||
nodeValue = ixmlNode_getNodeValue( nodeptr );
|
nodeValue = ixmlNode_getNodeValue(nodeptr);
|
||||||
|
switch (ixmlNode_getNodeType(nodeptr)) {
|
||||||
|
case eTEXT_NODE:
|
||||||
|
copy_with_escape(buf, nodeValue);
|
||||||
|
break;
|
||||||
|
|
||||||
switch ( ixmlNode_getNodeType( nodeptr ) ) {
|
case eCDATA_SECTION_NODE:
|
||||||
|
ixml_membuf_append_str(buf, "<![CDATA[");
|
||||||
|
ixml_membuf_append_str(buf, nodeValue);
|
||||||
|
ixml_membuf_append_str(buf, "]]>");
|
||||||
|
break;
|
||||||
|
|
||||||
case eTEXT_NODE:
|
case ePROCESSING_INSTRUCTION_NODE:
|
||||||
copy_with_escape( buf, nodeValue );
|
ixml_membuf_append_str(buf, "<?");
|
||||||
break;
|
ixml_membuf_append_str(buf, nodeName);
|
||||||
|
ixml_membuf_append_str(buf, " ");
|
||||||
|
copy_with_escape(buf, nodeValue);
|
||||||
|
ixml_membuf_append_str(buf, "?>\n");
|
||||||
|
break;
|
||||||
|
|
||||||
case eCDATA_SECTION_NODE:
|
case eDOCUMENT_NODE:
|
||||||
ixml_membuf_append_str( buf, "<![CDATA[" );
|
ixmlPrintDomTreeRecursive(
|
||||||
ixml_membuf_append_str( buf, nodeValue );
|
ixmlNode_getFirstChild(nodeptr), buf);
|
||||||
ixml_membuf_append_str( buf, "]]>" );
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case ePROCESSING_INSTRUCTION_NODE:
|
case eATTRIBUTE_NODE:
|
||||||
ixml_membuf_append_str( buf, "<?" );
|
ixml_membuf_append_str(buf, nodeName);
|
||||||
ixml_membuf_append_str( buf, nodeName );
|
ixml_membuf_append_str(buf, "=\"");
|
||||||
ixml_membuf_append_str( buf, " " );
|
copy_with_escape(buf, nodeValue);
|
||||||
copy_with_escape( buf, nodeValue );
|
ixml_membuf_append_str(buf, "\"");
|
||||||
ixml_membuf_append_str( buf, "?>\n" );
|
if (nodeptr->nextSibling != NULL) {
|
||||||
break;
|
ixml_membuf_append_str(buf, " ");
|
||||||
|
ixmlPrintDomTreeRecursive(nodeptr->nextSibling, buf);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case eDOCUMENT_NODE:
|
case eELEMENT_NODE:
|
||||||
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild
|
ixml_membuf_append_str(buf, "<");
|
||||||
( nodeptr ), buf );
|
ixml_membuf_append_str(buf, nodeName);
|
||||||
break;
|
if (nodeptr->firstAttr != NULL) {
|
||||||
|
ixml_membuf_append_str(buf, " ");
|
||||||
|
ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf);
|
||||||
|
}
|
||||||
|
child = ixmlNode_getFirstChild(nodeptr);
|
||||||
|
if (child != NULL &&
|
||||||
|
ixmlNode_getNodeType(child) == eELEMENT_NODE) {
|
||||||
|
ixml_membuf_append_str(buf, ">\r\n");
|
||||||
|
} else {
|
||||||
|
ixml_membuf_append_str(buf, ">");
|
||||||
|
}
|
||||||
|
// output the children
|
||||||
|
ixmlPrintDomTreeRecursive(
|
||||||
|
ixmlNode_getFirstChild(nodeptr), buf);
|
||||||
|
|
||||||
case eATTRIBUTE_NODE:
|
// Done with children. Output the end tag.
|
||||||
ixml_membuf_append_str( buf, nodeName );
|
ixml_membuf_append_str(buf, "</");
|
||||||
ixml_membuf_append_str( buf, "=\"" );
|
ixml_membuf_append_str(buf, nodeName);
|
||||||
copy_with_escape( buf, nodeValue );
|
|
||||||
ixml_membuf_append_str( buf, "\"" );
|
|
||||||
|
|
||||||
if( nodeptr->nextSibling != NULL ) {
|
sibling = ixmlNode_getNextSibling(nodeptr);
|
||||||
ixml_membuf_append_str( buf, " " );
|
if (sibling != NULL &&
|
||||||
ixmlPrintDomTreeRecursive( nodeptr->nextSibling, buf );
|
ixmlNode_getNodeType(sibling) == eTEXT_NODE) {
|
||||||
}
|
ixml_membuf_append_str( buf, ">" );
|
||||||
break;
|
} else {
|
||||||
|
ixml_membuf_append_str( buf, ">\r\n" );
|
||||||
|
}
|
||||||
|
ixmlPrintDomTreeRecursive(
|
||||||
|
ixmlNode_getNextSibling(nodeptr), buf);
|
||||||
|
break;
|
||||||
|
|
||||||
case eELEMENT_NODE:
|
default:
|
||||||
ixml_membuf_append_str( buf, "<" );
|
IxmlPrintf("(%s::ixmlPrintDomTreeRecursive) line %d: "
|
||||||
ixml_membuf_append_str( buf, nodeName );
|
"Warning, unknown node type %d\n",
|
||||||
|
__FILE__, __LINE__, ixmlNode_getNodeType(nodeptr));
|
||||||
if( nodeptr->firstAttr != NULL ) {
|
break;
|
||||||
ixml_membuf_append_str( buf, " " );
|
}
|
||||||
ixmlPrintDomTreeRecursive( nodeptr->firstAttr, buf );
|
}
|
||||||
}
|
|
||||||
|
|
||||||
child = ixmlNode_getFirstChild( nodeptr );
|
|
||||||
if( ( child != NULL )
|
|
||||||
&& ( ixmlNode_getNodeType( child ) ==
|
|
||||||
eELEMENT_NODE ) ) {
|
|
||||||
ixml_membuf_append_str( buf, ">\r\n" );
|
|
||||||
} else {
|
|
||||||
ixml_membuf_append_str( buf, ">" );
|
|
||||||
}
|
|
||||||
|
|
||||||
// output the children
|
|
||||||
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild
|
|
||||||
( nodeptr ), buf );
|
|
||||||
|
|
||||||
// Done with children. Output the end tag.
|
|
||||||
ixml_membuf_append_str( buf, "</" );
|
|
||||||
ixml_membuf_append_str( buf, nodeName );
|
|
||||||
|
|
||||||
sibling = ixmlNode_getNextSibling( nodeptr );
|
|
||||||
if( sibling != NULL
|
|
||||||
&& ixmlNode_getNodeType( sibling ) == eTEXT_NODE ) {
|
|
||||||
ixml_membuf_append_str( buf, ">" );
|
|
||||||
} else {
|
|
||||||
ixml_membuf_append_str( buf, ">\r\n" );
|
|
||||||
}
|
|
||||||
ixmlPrintDomTreeRecursive( ixmlNode_getNextSibling
|
|
||||||
( nodeptr ), buf );
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*================================================================
|
/*!
|
||||||
* ixmlPrintDomTree
|
* \brief Print a DOM tree.
|
||||||
* Print a DOM tree.
|
*
|
||||||
* Element, and Attribute nodes are handled differently.
|
* Element, and Attribute nodes are handled differently. We don't want to print
|
||||||
* We don't want to print the Element and Attribute nodes' sibling.
|
* the Element and Attribute nodes' sibling.
|
||||||
* External function.
|
*/
|
||||||
*
|
static void ixmlPrintDomTree(
|
||||||
*=================================================================*/
|
/*! [in] \todo documentation. */
|
||||||
void
|
IXML_Node *nodeptr,
|
||||||
ixmlPrintDomTree( IN IXML_Node * nodeptr,
|
/*! [in] \todo documentation. */
|
||||||
IN ixml_membuf * buf )
|
ixml_membuf *buf)
|
||||||
{
|
{
|
||||||
const char *nodeName = NULL;
|
const char *nodeName = NULL;
|
||||||
const char *nodeValue = NULL;
|
const char *nodeValue = NULL;
|
||||||
IXML_Node *child = NULL;
|
IXML_Node *child = NULL;
|
||||||
|
|
||||||
if( ( nodeptr == NULL ) || ( buf == NULL ) ) {
|
if (nodeptr == NULL || buf == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeName = ( const char * )ixmlNode_getNodeName( nodeptr );
|
nodeName = (const char *)ixmlNode_getNodeName(nodeptr);
|
||||||
nodeValue = ixmlNode_getNodeValue( nodeptr );
|
nodeValue = ixmlNode_getNodeValue(nodeptr);
|
||||||
|
switch (ixmlNode_getNodeType(nodeptr)) {
|
||||||
|
case eTEXT_NODE:
|
||||||
|
case eCDATA_SECTION_NODE:
|
||||||
|
case ePROCESSING_INSTRUCTION_NODE:
|
||||||
|
case eDOCUMENT_NODE:
|
||||||
|
ixmlPrintDomTreeRecursive(nodeptr, buf);
|
||||||
|
break;
|
||||||
|
|
||||||
switch ( ixmlNode_getNodeType( nodeptr ) ) {
|
case eATTRIBUTE_NODE:
|
||||||
|
ixml_membuf_append_str(buf, nodeName);
|
||||||
|
ixml_membuf_append_str(buf, "=\"");
|
||||||
|
copy_with_escape(buf, nodeValue);
|
||||||
|
ixml_membuf_append_str(buf, "\"");
|
||||||
|
break;
|
||||||
|
|
||||||
case eTEXT_NODE:
|
case eELEMENT_NODE:
|
||||||
case eCDATA_SECTION_NODE:
|
ixml_membuf_append_str(buf, "<");
|
||||||
case ePROCESSING_INSTRUCTION_NODE:
|
ixml_membuf_append_str(buf, nodeName);
|
||||||
case eDOCUMENT_NODE:
|
if (nodeptr->firstAttr != NULL) {
|
||||||
ixmlPrintDomTreeRecursive( nodeptr, buf );
|
ixml_membuf_append_str(buf, " ");
|
||||||
break;
|
ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf);
|
||||||
|
}
|
||||||
|
child = ixmlNode_getFirstChild(nodeptr);
|
||||||
|
if (child != NULL &&
|
||||||
|
ixmlNode_getNodeType(child) == eELEMENT_NODE) {
|
||||||
|
ixml_membuf_append_str(buf, ">\r\n");
|
||||||
|
} else {
|
||||||
|
ixml_membuf_append_str(buf, ">");
|
||||||
|
}
|
||||||
|
|
||||||
case eATTRIBUTE_NODE:
|
// output the children
|
||||||
ixml_membuf_append_str( buf, nodeName );
|
ixmlPrintDomTreeRecursive(
|
||||||
ixml_membuf_append_str( buf, "=\"" );
|
ixmlNode_getFirstChild(nodeptr), buf);
|
||||||
copy_with_escape( buf, nodeValue );
|
|
||||||
ixml_membuf_append_str( buf, "\"" );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case eELEMENT_NODE:
|
// Done with children. Output the end tag.
|
||||||
ixml_membuf_append_str( buf, "<" );
|
ixml_membuf_append_str(buf, "</");
|
||||||
ixml_membuf_append_str( buf, nodeName );
|
ixml_membuf_append_str(buf, nodeName);
|
||||||
|
ixml_membuf_append_str(buf, ">\r\n");
|
||||||
|
break;
|
||||||
|
|
||||||
if( nodeptr->firstAttr != NULL ) {
|
default:
|
||||||
ixml_membuf_append_str( buf, " " );
|
IxmlPrintf("(%s::ixmlPrintDomTree) line %d: "
|
||||||
ixmlPrintDomTreeRecursive( nodeptr->firstAttr, buf );
|
"Warning, unknown node type %d\n",
|
||||||
}
|
__FILE__, __LINE__, ixmlNode_getNodeType(nodeptr));
|
||||||
|
break;
|
||||||
child = ixmlNode_getFirstChild( nodeptr );
|
}
|
||||||
if( ( child != NULL )
|
|
||||||
&& ( ixmlNode_getNodeType( child ) == eELEMENT_NODE ) ) {
|
|
||||||
ixml_membuf_append_str( buf, ">\r\n" );
|
|
||||||
} else {
|
|
||||||
ixml_membuf_append_str( buf, ">" );
|
|
||||||
}
|
|
||||||
|
|
||||||
// output the children
|
|
||||||
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild( nodeptr ),
|
|
||||||
buf );
|
|
||||||
|
|
||||||
// Done with children. Output the end tag.
|
|
||||||
ixml_membuf_append_str( buf, "</" );
|
|
||||||
ixml_membuf_append_str( buf, nodeName );
|
|
||||||
ixml_membuf_append_str( buf, ">\r\n" );
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*================================================================
|
/*!
|
||||||
* ixmlDomTreetoString
|
* \brief Converts a DOM tree into a text string Element, and Attribute nodes
|
||||||
* Converts a DOM tree into a text string
|
* are handled differently. We don't want to print the Element and Attribute
|
||||||
* Element, and Attribute nodes are handled differently.
|
* nodes' sibling.
|
||||||
* We don't want to print the Element and Attribute nodes' sibling.
|
*/
|
||||||
* External function.
|
static void ixmlDomTreetoString(
|
||||||
*
|
/*! [in] \todo documentation. */
|
||||||
*=================================================================*/
|
IXML_Node *nodeptr,
|
||||||
void
|
/*! [in] \todo documentation. */
|
||||||
ixmlDomTreetoString( IN IXML_Node * nodeptr,
|
ixml_membuf *buf)
|
||||||
IN ixml_membuf * buf )
|
|
||||||
{
|
{
|
||||||
const char *nodeName = NULL;
|
const char *nodeName = NULL;
|
||||||
const char *nodeValue = NULL;
|
const char *nodeValue = NULL;
|
||||||
IXML_Node *child = NULL;
|
IXML_Node *child = NULL;
|
||||||
|
|
||||||
if( ( nodeptr == NULL ) || ( buf == NULL ) ) {
|
if (nodeptr == NULL || buf == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeName = ( const char * )ixmlNode_getNodeName( nodeptr );
|
nodeName = (const char *)ixmlNode_getNodeName(nodeptr);
|
||||||
nodeValue = ixmlNode_getNodeValue( nodeptr );
|
nodeValue = ixmlNode_getNodeValue(nodeptr);
|
||||||
|
|
||||||
switch ( ixmlNode_getNodeType( nodeptr ) ) {
|
switch (ixmlNode_getNodeType(nodeptr)) {
|
||||||
|
case eTEXT_NODE:
|
||||||
|
case eCDATA_SECTION_NODE:
|
||||||
|
case ePROCESSING_INSTRUCTION_NODE:
|
||||||
|
case eDOCUMENT_NODE:
|
||||||
|
ixmlPrintDomTreeRecursive(nodeptr, buf);
|
||||||
|
break;
|
||||||
|
|
||||||
case eTEXT_NODE:
|
case eATTRIBUTE_NODE:
|
||||||
case eCDATA_SECTION_NODE:
|
ixml_membuf_append_str(buf, nodeName);
|
||||||
case ePROCESSING_INSTRUCTION_NODE:
|
ixml_membuf_append_str(buf, "=\"");
|
||||||
case eDOCUMENT_NODE:
|
copy_with_escape(buf, nodeValue );
|
||||||
ixmlPrintDomTreeRecursive( nodeptr, buf );
|
ixml_membuf_append_str(buf, "\"");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case eATTRIBUTE_NODE:
|
case eELEMENT_NODE:
|
||||||
ixml_membuf_append_str( buf, nodeName );
|
ixml_membuf_append_str(buf, "<");
|
||||||
ixml_membuf_append_str( buf, "=\"" );
|
ixml_membuf_append_str(buf, nodeName);
|
||||||
copy_with_escape( buf, nodeValue );
|
if (nodeptr->firstAttr != NULL) {
|
||||||
ixml_membuf_append_str( buf, "\"" );
|
ixml_membuf_append_str(buf, " ");
|
||||||
break;
|
ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf);
|
||||||
|
}
|
||||||
|
child = ixmlNode_getFirstChild(nodeptr);
|
||||||
|
if (child != NULL &&
|
||||||
|
ixmlNode_getNodeType(child) == eELEMENT_NODE) {
|
||||||
|
ixml_membuf_append_str(buf, ">");
|
||||||
|
} else {
|
||||||
|
ixml_membuf_append_str(buf, ">");
|
||||||
|
}
|
||||||
|
|
||||||
case eELEMENT_NODE:
|
// output the children
|
||||||
ixml_membuf_append_str( buf, "<" );
|
ixmlPrintDomTreeRecursive(ixmlNode_getFirstChild(nodeptr), buf);
|
||||||
ixml_membuf_append_str( buf, nodeName );
|
|
||||||
|
|
||||||
if( nodeptr->firstAttr != NULL ) {
|
// Done with children. Output the end tag.
|
||||||
ixml_membuf_append_str( buf, " " );
|
ixml_membuf_append_str(buf, "</");
|
||||||
ixmlPrintDomTreeRecursive( nodeptr->firstAttr, buf );
|
ixml_membuf_append_str(buf, nodeName);
|
||||||
}
|
ixml_membuf_append_str(buf, ">");
|
||||||
|
break;
|
||||||
|
|
||||||
child = ixmlNode_getFirstChild( nodeptr );
|
default:
|
||||||
if( ( child != NULL )
|
IxmlPrintf("(%s::ixmlDomTreetoString) line %d: "
|
||||||
&& ( ixmlNode_getNodeType( child ) == eELEMENT_NODE ) ) {
|
"Warning, unknown node type %d\n",
|
||||||
ixml_membuf_append_str( buf, ">" );
|
__FILE__, __LINE__, ixmlNode_getNodeType(nodeptr));
|
||||||
} else {
|
break;
|
||||||
ixml_membuf_append_str( buf, ">" );
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// output the children
|
|
||||||
ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild( nodeptr ),
|
|
||||||
buf );
|
|
||||||
|
|
||||||
// Done with children. Output the end tag.
|
|
||||||
ixml_membuf_append_str( buf, "</" );
|
|
||||||
ixml_membuf_append_str( buf, nodeName );
|
|
||||||
ixml_membuf_append_str( buf, ">" );
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*================================================================
|
|
||||||
* ixmlLoadDocumentEx
|
|
||||||
* Parses the given file, and returns the DOM tree from it.
|
|
||||||
* External function.
|
|
||||||
*
|
|
||||||
*=================================================================*/
|
|
||||||
int
|
|
||||||
ixmlLoadDocumentEx( IN const char *xmlFile,
|
|
||||||
IXML_Document ** doc )
|
|
||||||
{
|
|
||||||
|
|
||||||
if( ( xmlFile == NULL ) || ( doc == NULL ) ) {
|
|
||||||
return IXML_INVALID_PARAMETER;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Parser_LoadDocument( doc, xmlFile, TRUE );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*================================================================
|
|
||||||
* ixmlLoadDocument
|
|
||||||
* Parses the given file, and returns the DOM tree from it.
|
|
||||||
* External function.
|
|
||||||
*
|
|
||||||
*=================================================================*/
|
|
||||||
IXML_Document *
|
|
||||||
ixmlLoadDocument( IN const char *xmlFile )
|
|
||||||
{
|
|
||||||
|
|
||||||
IXML_Document *doc = NULL;
|
|
||||||
|
|
||||||
ixmlLoadDocumentEx( xmlFile, &doc );
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*================================================================
|
|
||||||
* ixmlPrintDocument
|
|
||||||
* Prints entire document, prepending XML prolog first.
|
|
||||||
* Puts lots of white spaces.
|
|
||||||
* External function.
|
|
||||||
*
|
|
||||||
*=================================================================*/
|
|
||||||
|
|
||||||
DOMString
|
|
||||||
ixmlPrintDocument(IXML_Document *doc)
|
|
||||||
{
|
|
||||||
IXML_Node* rootNode = ( IXML_Node * )doc;
|
|
||||||
ixml_membuf memBuf;
|
|
||||||
ixml_membuf *buf = &memBuf;
|
|
||||||
|
|
||||||
if( rootNode == NULL ) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ixml_membuf_init( buf );
|
|
||||||
ixml_membuf_append_str( buf, "<?xml version=\"1.0\"?>\r\n" );
|
|
||||||
ixmlPrintDomTree( rootNode, buf );
|
|
||||||
return buf->buf;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*================================================================
|
|
||||||
* ixmlPrintNode
|
|
||||||
* Print DOM tree under node. Puts lots of white spaces
|
|
||||||
* External function.
|
|
||||||
*
|
|
||||||
*=================================================================*/
|
|
||||||
DOMString
|
|
||||||
ixmlPrintNode( IN IXML_Node * node )
|
|
||||||
{
|
|
||||||
|
|
||||||
ixml_membuf memBuf;
|
|
||||||
ixml_membuf *buf = &memBuf;
|
|
||||||
|
|
||||||
if( node == NULL ) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ixml_membuf_init( buf );
|
|
||||||
ixmlPrintDomTree( node, buf );
|
|
||||||
return buf->buf;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*================================================================
|
|
||||||
* ixmlDocumenttoString
|
|
||||||
* converts DOM tree under node to text string,
|
|
||||||
* prepending XML prolog first.
|
|
||||||
* External function.
|
|
||||||
*
|
|
||||||
*=================================================================*/
|
|
||||||
|
|
||||||
DOMString
|
|
||||||
ixmlDocumenttoString(IXML_Document *doc)
|
|
||||||
{
|
|
||||||
IXML_Node* rootNode = ( IXML_Node * )doc;
|
|
||||||
ixml_membuf memBuf;
|
|
||||||
ixml_membuf *buf = &memBuf;
|
|
||||||
|
|
||||||
if( rootNode == NULL ) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ixml_membuf_init( buf );
|
|
||||||
ixml_membuf_append_str( buf, "<?xml version=\"1.0\"?>\r\n" );
|
|
||||||
ixmlDomTreetoString( rootNode, buf );
|
|
||||||
return buf->buf;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*================================================================
|
|
||||||
* ixmlNodetoString
|
|
||||||
* converts DOM tree under node to text string
|
|
||||||
* External function.
|
|
||||||
*
|
|
||||||
*=================================================================*/
|
|
||||||
DOMString
|
|
||||||
ixmlNodetoString( IN IXML_Node * node )
|
|
||||||
{
|
|
||||||
|
|
||||||
ixml_membuf memBuf;
|
|
||||||
ixml_membuf *buf = &memBuf;
|
|
||||||
|
|
||||||
if( node == NULL ) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ixml_membuf_init( buf );
|
|
||||||
ixmlDomTreetoString( node, buf );
|
|
||||||
return buf->buf;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*================================================================
|
|
||||||
* ixmlRelaxParser
|
|
||||||
* Makes the XML parser more tolerant to malformed text.
|
|
||||||
* External function.
|
|
||||||
*
|
|
||||||
*=================================================================*/
|
|
||||||
void
|
|
||||||
ixmlRelaxParser(char errorChar)
|
|
||||||
{
|
|
||||||
Parser_setErrorChar( errorChar );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*================================================================
|
int ixmlLoadDocumentEx(const char *xmlFile, IXML_Document **doc)
|
||||||
* ixmlParseBufferEx
|
|
||||||
* Parse xml file stored in buffer.
|
|
||||||
* External function.
|
|
||||||
*
|
|
||||||
*=================================================================*/
|
|
||||||
int
|
|
||||||
ixmlParseBufferEx( IN const char *buffer,
|
|
||||||
IXML_Document ** retDoc )
|
|
||||||
{
|
{
|
||||||
|
if (xmlFile == NULL || doc == NULL) {
|
||||||
|
return IXML_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
if( ( buffer == NULL ) || ( retDoc == NULL ) ) {
|
return Parser_LoadDocument(doc, xmlFile, TRUE);
|
||||||
return IXML_INVALID_PARAMETER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( buffer[0] == '\0' ) {
|
|
||||||
return IXML_INVALID_PARAMETER;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Parser_LoadDocument( retDoc, buffer, FALSE );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*================================================================
|
|
||||||
* ixmlParseBuffer
|
|
||||||
* Parse xml file stored in buffer.
|
|
||||||
* External function.
|
|
||||||
*
|
|
||||||
*=================================================================*/
|
|
||||||
IXML_Document *
|
|
||||||
ixmlParseBuffer( IN const char *buffer )
|
|
||||||
{
|
|
||||||
IXML_Document *doc = NULL;
|
|
||||||
|
|
||||||
ixmlParseBufferEx( buffer, &doc );
|
IXML_Document *ixmlLoadDocument(const char *xmlFile)
|
||||||
return doc;
|
{
|
||||||
|
IXML_Document *doc = NULL;
|
||||||
|
|
||||||
|
ixmlLoadDocumentEx(xmlFile, &doc);
|
||||||
|
|
||||||
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*================================================================
|
|
||||||
* ixmlCloneDOMString
|
|
||||||
* Clones a DOM String.
|
|
||||||
* External function.
|
|
||||||
*
|
|
||||||
*=================================================================*/
|
|
||||||
DOMString
|
|
||||||
ixmlCloneDOMString( IN const DOMString src )
|
|
||||||
{
|
|
||||||
if( src == NULL ) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ( strdup( src ) );
|
DOMString ixmlPrintDocument(IXML_Document *doc)
|
||||||
|
{
|
||||||
|
IXML_Node* rootNode = (IXML_Node *)doc;
|
||||||
|
ixml_membuf memBuf;
|
||||||
|
ixml_membuf *buf = &memBuf;
|
||||||
|
|
||||||
|
if(rootNode == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ixml_membuf_init(buf);
|
||||||
|
ixml_membuf_append_str(buf, "<?xml version=\"1.0\"?>\r\n");
|
||||||
|
ixmlPrintDomTree(rootNode, buf);
|
||||||
|
|
||||||
|
return buf->buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*================================================================
|
|
||||||
* ixmlFreeDOMString
|
DOMString ixmlPrintNode(IXML_Node *node)
|
||||||
* Frees a DOM String.
|
|
||||||
* External function.
|
|
||||||
*
|
|
||||||
*=================================================================*/
|
|
||||||
void
|
|
||||||
ixmlFreeDOMString( IN DOMString buf )
|
|
||||||
{
|
{
|
||||||
if( buf != NULL ) {
|
ixml_membuf memBuf;
|
||||||
free( buf );
|
ixml_membuf *buf = &memBuf;
|
||||||
}
|
|
||||||
|
if (node == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ixml_membuf_init(buf);
|
||||||
|
ixmlPrintDomTree(node, buf);
|
||||||
|
|
||||||
|
return buf->buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DOMString ixmlDocumenttoString(IXML_Document *doc)
|
||||||
|
{
|
||||||
|
IXML_Node* rootNode = (IXML_Node *)doc;
|
||||||
|
ixml_membuf memBuf;
|
||||||
|
ixml_membuf *buf = &memBuf;
|
||||||
|
|
||||||
|
if(rootNode == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ixml_membuf_init(buf);
|
||||||
|
ixml_membuf_append_str(buf, "<?xml version=\"1.0\"?>\r\n");
|
||||||
|
ixmlDomTreetoString(rootNode, buf);
|
||||||
|
|
||||||
|
return buf->buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DOMString ixmlNodetoString(IXML_Node *node)
|
||||||
|
{
|
||||||
|
ixml_membuf memBuf;
|
||||||
|
ixml_membuf *buf = &memBuf;
|
||||||
|
|
||||||
|
if (node == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ixml_membuf_init(buf);
|
||||||
|
ixmlDomTreetoString(node, buf);
|
||||||
|
|
||||||
|
return buf->buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ixmlRelaxParser(char errorChar)
|
||||||
|
{
|
||||||
|
Parser_setErrorChar(errorChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ixmlParseBufferEx(const char *buffer, IXML_Document **retDoc)
|
||||||
|
{
|
||||||
|
if (buffer == NULL || retDoc == NULL) {
|
||||||
|
return IXML_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer[0] == '\0') {
|
||||||
|
return IXML_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Parser_LoadDocument(retDoc, buffer, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
IXML_Document *ixmlParseBuffer(const char *buffer)
|
||||||
|
{
|
||||||
|
IXML_Document *doc = NULL;
|
||||||
|
|
||||||
|
ixmlParseBufferEx(buffer, &doc);
|
||||||
|
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DOMString ixmlCloneDOMString(const DOMString src)
|
||||||
|
{
|
||||||
|
if (src == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return strdup(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ixmlFreeDOMString(DOMString buf)
|
||||||
|
{
|
||||||
|
if (buf != NULL) {
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user