I want to restrict xml with a schema to a specific set. I read this tutorial
http://www.w3schools.com/schema/schema_facets.asp
This seems to be what I want. So, I'm using Qt to validate this xml
<car>BMW</car>
Here is the pertinent source code.
QXmlSchema schema;
schema.load( QUrl("file:///workspace/QtExamples/ValidateXSD/car.xsd") );
if ( schema.isValid() ) {
    QXmlSchemaValidator validator( schema );
    if ( validator.validate( QUrl("file:///workspace/QtExamples/ValidateXSD/car.xml") ) ) {
        qDebug() << "instance is valid";
    } else {
        qDebug() << "instance is invali开发者_如何转开发d";
    }
} else {
    qDebug() << "schema is invalid";
}
I expected the xml to match the schema definition. Unexpectedly, QxmlSchemaValidator complains.
Error XSDError in file:///workspace/QtExamples/ValidateXSD/car.xml, at line 1, column 5: Content of element car does not match its type definition: String content is not listed in the enumeration facet..
instance is invalid
I suspect this is a braino. How does one restrict xml with an XML Schema?
Here is the xsd from the tutorial:
<xs:element name="car">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:enumeration value="Audi"/>
      <xs:enumeration value="Golf"/>
      <xs:enumeration value="BMW"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>
The problem had to do with whitespace. As formatted on this, it actuals works. However, if the start tag, value and end tag are on separate lines, it is invalid.
-jk
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论