[xsd-users] Re: xml_schema::flags::no_xml_declaration leaves blank line

Boris Kolpackov boris at codesynthesis.com
Wed Dec 16 06:36:02 EST 2009


Hi Stephen,

Stephen James <Stephen.James at genband.com> writes:

> I am serializing my xml with:
> 
> acbtcap(ss, out, map, "UTF-8", xml_schema::flags::no_xml_declaration);
> 
> and instead of omitting the <?xml ...> line it just omits the contents.
> I am still left with the blank line (\n).

This appears to be a bug in the Xerces-C++ pretty-printer. I have filed
a report:

https://issues.apache.org/jira/browse/XERCESC-1902

Xerces-C++ 3.1.0 is already in the release candidate stage so unfortunately
the fix will have to wait until the release after it.

The two possible workarounds are:

1. Disable pretty-printing.

2. Remove the leading newline from the resulting XML, for example:

ostringstream ss;
acbtcap(ss, out, map, "UTF-8", xml_schema::flags::no_xml_declaration);

string s;
const string& tmp (ss.str ());

if (!tmp.empty () && tmp[0] == '\n')
  s.assign (tmp, 1, tmp.size () - 1);
else
  s = tmp;

Or, if you need a C string (for example, to write it to a socket), then
you can avoid copying:

const string& tmp (ss.str ());
const char* s (tmp.c_str ());

if (!tmp.empty () && tmp[0] == '\n')
  s++;


> Also, how can I eliminate the xmlns: and xsi: contents below (bandwidth
> limited transport.
> 
> <acbtcap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="acbtcap.xsd"/>

You have something like this in your code:

map[""].schema = "acbtcap.xsd";

Simply remove this like.

Boris



More information about the xsd-users mailing list