[xsd-users] serialize library objects to ofstream

Schmilinsky, Remsy Remsy.Schmilinsky at ccra-adrc.gc.ca
Fri Sep 22 10:26:33 EDT 2006


Hi. I'm trying to combine the library and streaming examples so that I can serialize books into an xml file from memory representation. The code below compiles fine, but when I run it I get "no mapping provided for a namespace".

I compile library.xsd like this:

/usr/local/bin/xsd cxx-tree --generate-inline --generate-ostream --generate-serialization --suppress-parsing --root-element-all library.xsd

please help

        std::ofstream ofs;
        ofs.exceptions (ios_base::badbit | ios_base::failbit);
        ofs.open ("out.xml");
        
        ofs << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl
        << "<lib:catalog>" << endl;        
        
        xercesc::XMLPlatformUtils::Initialize ();
        
        xml_schema::namespace_infomap map;
        
        catalog c;
        
        book b(20530902,                // ISBN
        title("The Elements of Style"), // Title
        genre::reference,               // Genre
        "ES");                          // ID
        
        author strunk("William Strunk, Jr.", "1869-07-01");
        strunk.died("1946-09-26");
        
        b.author().push_back(strunk);
        c.book().push_back(b);
        
        catalog_ (ofs,
                  c,
                  map,
                  "UTF-8",
                  xml_schema::flags::dont_initialize |
                  xml_schema::flags::no_xml_declaration);
                  
        ofs << "</lib:catalog>" << endl;
        
        xercesc::XMLPlatformUtils::Terminate ();



More information about the xsd-users mailing list