2

I have this code

    if(genericPtr->type == XML_ATTRIBUTE_NODE){
        xmlAttrPtr attr = (xmlAttrPtr)genericPtr;
        printf("\n str %s\n", (const char *)attr->children->content);
    }

    xmlBufferPtr bufferPtr = xmlBufferCreate();
    if (IsXmlNsPtr(genericPtr)){
        xmlNodeDump(bufferPtr, NULL, (xmlNodePtr)genericPtr, 0, format);
    }else{
        xmlNodeDump(bufferPtr, ((xmlStdPtr)genericPtr)->doc, (xmlNodePtr)genericPtr, 0, format);
    }

    printf("\n str2 %s\n", (const char *)bufferPtr->content);

The result is

str чатрум@muc.chat.quickblox.com/300

str2  to="чатрум@muc.chat.quickblox.com/300"

In result i need чатрум instead

чатрум

how can i do this?

Rubycon
  • 18,156
  • 10
  • 49
  • 70

1 Answers1

2

Try xmlNodeDumpOutput which allows you to specify an encoding. Note that it uses an xmlOutputBuffer instead of an xmlBuffer. Another useful function is xmlXPathCastNodeToString which returns the XPath string value of a node as xmlChar.

nwellnhof
  • 32,319
  • 7
  • 89
  • 113
  • Hi, I'm using exactly this method, the xmlNodeDumpOutput but even declaring the required output encoding I have always an UTF-8 output. Can you point me the right direction? – Mr.Gate Sep 08 '14 at 16:14
  • @Mr.Gate What encoding are you trying to use? Are you sure it's supported by your libxml2 installation? – nwellnhof Sep 08 '14 at 21:47