Cannot read an attribute from an xml-file.

  • Anonymous - 2011-01-19


    I have a bit of a problem reading an xml-file and I hope you can help. It would be greatly appreciated :)

    The xml-file contains localisation data and looks like this:

    <?xml version="1.0"?>
    <Locale version="1.0.0">
        <Languages count="4">
            <Language name="Deutsch" code="de-DE" />
            <Language name="English" code="en-US" />
            <Language name="Deutsch" code="de-DE" />
            <Language name="English" code="en-US" />
        <string identifier="AppName">
            <encoding code="de-DE" value="A&#x0;n&#x0;w&#x0;e&#x0;n&#x0;d&#x0;u&#x0;n&#x0;g&#x0;" />
            <encoding code="en-US" value="A&#x0;p&#x0;p&#x0;l&#x0;i&#x0;c&#x0;a&#x0;t&#x0;i&#x0;o&#x0;n&#x0;" />

    My code to read the value attribute looks like this:

    TiXmlHandle docHandle( &doc );
    TiXmlElement* encodingElem = docHandle.FirstChild( "Locale" ).FirstChild( "string" ).FirstChild("encoding").ToElement();
    if ( encodingElem )
        // do something useful
        CString strValue;
        const char* strAttr = encodingElem->Attribute( "value" );

    This only returns the first character of the string in value. I checked the memory and it contains the rest of the string:

    strAttr 65 'A' const char
    strAttr 0 const char
    strAttr 110 'n' const char
    strAttr 0 const char
    strAttr 119 'w' const char
    strAttr 0 const char
    strAttr 101 'e' const char

    I am guessing the format of the string might be UTF-16?
    I think the 0 in position 1 is interpreted as the end of the string.
    How can I read this string properly?

    Thank you!

  • Anonymous - 2011-01-19

    meh, I removed the &#x0; bits using a text editor and now the text reads fine. That's all I wanted at the moment.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks