UaXmlDocument - output XML is padded with spaces and \n's

Questions regarding the use of the C++ SDK for Server or Client development or integration into customer products ...

Moderator: uasdkcpp

Post Reply
Yorwick
Jr. Member
Jr. Member
Posts: 3
Joined: 31 Oct 2017, 12:59

UaXmlDocument - output XML is padded with spaces and \n's

Post by Yorwick »

Dear Unified Automation Support,

I have a use case where I need to use an OPC UA method to return a large amount of data in XML format. I have discovered that if I build the XML using UaXmlDocument & related APIs and then return a string with xmlDocument.dumpXmlFile then the string gets padded with extra spaces and newline characters. I expect this was done to improve readability of the XML output, but I don't really want to inflate the size of what gets sent on the wire. Is there a way to switch off the extra padding?

Thanks

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re: UaXmlDocument - output XML is padded with spaces and \n'

Post by Support Team »

Hello Yorwick,

the method UaXmlDocument::dumpXmlFile doesn't take any parameter that allows to change the format.

You can just strip the string manually:

Code: Select all

    UaXmlDocument xmlDoc;
    ...
    result = xmlDoc.dumpXmlFile(&szContent, size);
    if (result == 0)
    {
        UaUniString uniStrTmp(szContent);
        // remove all whitespaces
        uniStrTmp = uniStrTmp.replace(" ", "");
        // remove all newlines
        uniStrTmp = uniStrTmp.replace("\n", "");
    }
Note that this code may impact performance.
Best regards
Unified Automation Support Team

Post Reply