[xsd-users] Re: Never failing in Parsing

Boris Kolpackov boris at codesynthesis.com
Thu Aug 27 09:32:08 EDT 2009


Hi,

I see you have figured out how to serialize the object model back
to XML. In the future, please don't send multiple emails asking
essentially the same question. One is enough and someone will reply
when/if they have time. If you need more predictable assistance, I
suggest you consider purchasing a Priority Support contract:

http://www.codesynthesis.com/support/


ss ak <ssak22 at gmail.com> writes:

> but what ever values given,parser never gives an exception...

You mean serializer, not parser? Your code below doesn't perform
any parsing, only serialization.


> xml_schema::namespace_infomap map;
> 
> map[""].schema = "test.xsd";
> 
> std::ostringstream oss;
> 
> nt_(oss, var_nt, map);  //here nt is my class generated
> 
> std::string xml (oss.str ());
> 
> printf("\n XML %s",xml.c_str()); //here it prints the xml valid or not

The C++/Tree mapping doesn't support automatic XML Schema validation 
during serialization. What you can do, however, is re-parse the XML
to make sure it is valid. So given the code above, you can add:

try
{
  std::istringstream iss (xml);
  nt_(iss, "<in-memory-xml>");
}
catch (const xml_schema::exception& e)
{
  std::cerr << e << std::endl;
}

Boris




More information about the xsd-users mailing list