[xsd-users] Limiting field sizes when serializing to DOM documents

Matt Burnham matt.burnham.ctr at mhpcc.hpc.mil
Thu Jul 12 14:50:09 EDT 2007


Boris,

I have the following schema (only the relevant parts shown):

<xs:element name="event">
    <xs:complexType>
        <xs:attribute name="version" use="required">
            <xs:simpleType>
                <xs:restriction base="xs:decimal">
                    <xs:minInclusive value="2"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
    </xs:complexType>
</xs:element>

I create an in-memory tree (my_event) and then serialize it to a DOM 
document to output XML:

std::ostringstream buff;
xml_schema::namespace_infomap nsm;
xercesc::XMLPlatformUtils::Initialize();
// serialize the event into a DOM document
xsd::cxx::xml::dom::auto_ptr<xercesc::DOMDocument> event_doc( 
event_(my_event, nsm) );
// write the resulting DOM document to XML
xercesc::DOMImplementation* impl( 
xercesc::DOMImplementationRegistry::getDOMImplementation(xsd::cxx::xml::string("LS").c_str()) 
);
std::auto_ptr<xercesc::DOMWriter> writer( impl->createDOMWriter() );
xsd::cxx::xml::dom::ostream_format_target ft( buff );
writer->writeNode( &ft, *event_doc );
xercesc::XMLPlatformUtils::Terminate();
std::string xml_str = buff.str();

And I get the following:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<event version="2.000000000000000000000000">
</event>

Is there some way the enforce the <xs:minInclusive value="2"/> 
restriction when serializing to a DOM document?

Thanks,
Matt




More information about the xsd-users mailing list