无法通过xmlReaderForMemory api进行解析

时间:2013-08-27 08:29:00

标签: libxml2

我的代码生成以下字符串

XmlWriter obj1;
obj1.StartDocWriting("MyObject.xml");
obj1.SetRootNode("Object");
obj1.CreateChildNodeToRootWithProperty("age","20");         
obj1.CreateChildNodeToRootWithProperty("name","xyz");
obj1.xml_to_string(outbuf);

o / p xml string,

<?xml version="1.0"?>
<Object><age>20</age><name>xyz</name></Object>

当我尝试解析它时,我收到以下错误,

  

实体:第3行:解析器错误:结尾处的额外内容   文件

Here is my parsing code,

std:string inbuf = "<?xml version="1.0"?>
<Object><age>20</age><name>xyz</name></Object>"

 XmlTextReader obj1;
 xmlTextReaderPtr readPtr =  obj1.parseBuffer(inbuf.c_str(),10000);

xmlTextReaderPtr XmlTextReader::parseBuffer( const char *aInBuffer,
                                             int aInSize,
                                             const char * aInUrl,
                                             const char * aInEncoding,
                                             int aInOptions )
{
    xmlReader = xmlReaderForMemory( aInBuffer, aInSize, aInUrl, aInEncoding, aInOptions );
    if( xmlReader == NULL )
    {
       printf("reader is null");
       // LOG(LOG_INFO, "parseBuffer:: xmlReaderForMemory return NULL\n");
    }
    return xmlReader;
}  

0 个答案:

没有答案