Here is the schema file sample.xsd
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="shipordertype">
<xs:attribute name="orderid" type="xs:string" default="abc"/>开发者_开发百科
</xs:complexType>
<xs:element name="shiporder" type="shipordertype"/>
</xs:schema>
Here is the XML file sample.XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<shiporder
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="sample.xsd">
</shiporder>
I load this XML in code, and read "orderid" attribute, I can not get value "abc", but a null string. What's wrong? How to get the default value? Is it necessary to read the schema file in code? I'm a beginner at xsd.
Thanks, Jack
At least you need to parse the XML document with a schema validating parser. You didn't mention which language, etc, you are using, but if you use java, then it should work with a schema enabled javax.xml.DOMBuilder
精彩评论