2013-04-03 44 views
2

假如我有可能包含像這樣的XSD:如何訪問XML模式中的枚舉ID(使用xerces-c)?

<simpleType name="CELESTIAL_IMPORIUM_CATEGORY"> 
    <restriction base="integer"> 
     <enumeration id="BELONGING_TO_THE_EMPEROR" value="8001"/> 
     <enumeration id="EMBALMED"     value="8002"/> 
     <enumeration id="TRAINED"     value="8003"/> 
     <enumeration id="SUCKLING_PIGS"   value="8004"/> 
    </restriction> 
</simpleType> 

假設我希望能夠得到這兩個枚舉值的保持,他們的名字(這是在ID屬性)。我試圖弄清楚這是否可能。假設再進一步,我可能會使用xerces-c(3.1.1,比如說),更具體地說,是使用xercesc/framework/psvi中的類。我已經有大約初步捅,事情不是看起來很有希望:

  • 它看起來像XSSimpleTypeDefinition提供了通過getMultiValueFacets()
  • 然而,這會返回一個XSMultiValueFacet,這似乎只是提供接入訪問枚舉細節到值(和註釋)。

有沒有,也許,我失蹤了?

回答

0

我不認爲你有什麼遺漏(但我不熟悉Xerces-C內部)。 XSD規範詳細地定義了模式後驗證信息集和模式組件的抽象結構,但它並不要求驗證器提供對任何一個特定部分的訪問權限,更沒有指定用於這樣做的API。 (在關鍵時刻,來自有影響力的公司的工作組成員咆哮道:「我們不需要任何強化API規範」,而且房間中的所有供應商都同意)。因此,您所訪問的內容取決於特定軟件您正在使用,您可以通過它訪問它。

然而,即使是最徹底的API,也不可能提供對xsd:枚舉元素的ID屬性值的訪問--ID屬性不對應於簡單類型組件的任何部分,幾乎全部模式信息API的設計者可能會將其視爲組件的XML表示的副產品,而沒有任何內在的興趣。

如果您有權訪問定義您所使用的模式的模式文檔,當然,您始終可以使用普通的XML工具來查找您感興趣的ID;這是使架構文檔成爲XML文檔的原因之一。

1

Genericode是一個很好的例子,它說明了如何在XSD中以這種仍然有效的方式包含代碼,ID和描述。 https://www.oasis-open.org/committees/tc_home.php?wg_abbrev=codelist

下面是完整列表快速樣品去here

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ccts="urn:un:unece:uncefact:documentation:2" elementFormDefault="qualified" attributeFormDefault="unqualified"> 
    <xs:simpleType name="CurrencyCodeContentType"> 
    <xs:restriction base="xs:token"><xs:enumeration value="AED"><xs:annotation><xs:documentation> 
         <ccts:CodeName>Dirham</ccts:CodeName> 
         <ccts:CodeDescription/> 
        </xs:documentation> 
       </xs:annotation> 
      </xs:enumeration><xs:enumeration value="AFN"><xs:annotation><xs:documentation> 
         <ccts:CodeName>Afghani</ccts:CodeName> 
         <ccts:CodeDescription/> 
        </xs:documentation> 
       </xs:annotation> 
      </xs:enumeration><xs:enumeration value="ALL"><xs:annotation><xs:documentation> 
         <ccts:CodeName>Lek</ccts:CodeName> 
         <ccts:CodeDescription/> 
        </xs:documentation> 
       </xs:annotation> 
      </xs:enumeration><xs:enumeration value="AMD"><xs:annotation><xs:documentation> 
         <ccts:CodeName>Dram</ccts:CodeName> 
         <ccts:CodeDescription/> 
        </xs:documentation> 
       </xs:annotation> 
      </xs:enumeration><xs:enumeration value="ANG"><xs:annotation><xs:documentation> 
         <ccts:CodeName>Netherlands Antillian Guilder</ccts:CodeName> 
         <ccts:CodeDescription/> 
        </xs:documentation> 
       </xs:annotation> 
      </xs:enumeration> 
     </xs:restriction> 
    </xs:simpleType> 
</xs:schema> 
+0

還沒有真正進入低谷的Xerces-C – SteakOverflow