我有一個xml與XML模式。 xml架構定義了一個具有2個可選屬性的抽象複合類型,這些屬性具有默認值。然後我有幾個複雜的類型擴展了基礎類型。最後定義類型的節點。 所以我加載XML,當我解析每個節點時,可選屬性根本不存在。 我試着與命名空間打打鬧鬧,甚至:任何使XML中的默認屬性值在Flex中基於XSD架構解析的方法?
XML.ignoreProcessingInstructions = false;
沒有運氣。這個人在codingforums上遇到過類似的事情,但那與5年前相似。使用firefox 3.0.11時,發生了同樣的情況 - xml顯示爲沒有默認屬性。 現在我在代碼中設置默認值,但沒有辦法使它們可以從xml架構中獲得?
示例XML-模式:
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.myorg.org" xmlns:tns="http://www.myorg.org" elementFormDefault="qualified">
<element name="config" type="tns:FieldsNode"></element>
<complexType name="FieldsNode">
<choice minOccurs="0" maxOccurs="unbounded">
<element name="ImagePicker" type="tns:ImagePickerNode"
maxOccurs="unbounded" minOccurs="0">
</element>
</choice>
</complexType>
<complexType name="FieldBase">
<attribute use="required" name="id" type="string"></attribute>
<attribute use="optional" default="true" name="mandatory"
type="boolean">
</attribute>
<attribute default="3" name="colspan" type="int" use="optional"></attribute>
</complexType>
<complexType name="ImagePickerNode">
<complexContent>
<extension base="tns:FieldBase">
<attribute name="maxWidth" type="int" use="required"></attribute>
<attribute name="maxHeight" type="int" use="required"></attribute>
</extension>
</complexContent>
</complexType>
示例XML:
<config xmlns="http://www.myorg.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.myorg.org test.xsd">
<ImagePicker id="somePicker" maxHeight="10" maxWidth="12"/>
<ImagePicker id="someOtherPicker" maxHeight="100" maxWidth="212" colspan="1" mandatory="false"/>
</config>
編輯:增加了樣本XML和模式。
XML的示例可能有所幫助 – Stiggler 2009-06-17 03:11:43