xml是常用的一種資料檔案格式,它的定義檔案為xml schema definition(xsd),那麼怎麼驗證乙個xml是否符合它的schema定義呢?
本文給出c#的**實現。
儲存在xml.xml檔案中
儲存在xsd.xsd檔案中<?xml version="1.0" encoding="utf-8"
?>
10age>
2018-01-01date>
111regex>
---10--gmonth>
englishlanguage>
./news.htmlanyuri>
xml>
下面**在console project中實現<?xml version="1.0"
?>
xmlns:xs="">
name="xml">
name="age">
base="xs:decimal">
value="10"/>
value="20"/>
value="30"/>
xs:restriction>
xs:******type>
xs:element>
name="date">
base="xs:date">
value="2018-01-01z"/>
xs:restriction>
xs:******type>
xs:element>
name="regex">
base="xs:string">
value="[0-9][0-9][0-9]"/>
xs:restriction>
xs:******type>
xs:element>
name="gmonth"
type="xs:gmonth"/>
name="language"
type="xs:language"/>
name="anyuri"
type="xs:anyuri"/>
xs:sequence>
xs:complextype>
xs:element>
xs:schema>
class
program
private
static
void
verifyxml(string xsdfile, string xmlfile, ref
string exceptionmessage)
});doc.validate(eventhandler);
exceptionmessage = errormessage;
}private
static xmldocument loadxml(string xmlfile)
private
static xmlschemaset loadxmlschmeafromxsdfile(string path)
}
PHP DOM驗證xml文件是否符合DTD驗證
validate.php header content type text html charset utf 8 dom new domdocument 1.0 utf 8 dom validateonparse true 第一種方法通過屬性驗證 強制載入外部dtd 是否通過dtd檔案驗證xml文件...
C 使用xsd檔案驗證XML 格式是否正確
c 使用xsd檔案驗證xml 格式是否正確 核心示例 c 建立xmldocument xmldocument doc new xmldocument 建立宣告段 如 建立乙個根節點 kytresults xmlelement results doc.createelement kytresults ...
C 使用xsd檔案驗證XML 格式是否正確
建立xmldocument xmldocument doc new xmldocument 建立宣告段 如 建立乙個根節點 kytresults xmlelement results doc.createelement kytresults 建立 resultsstatus xmlnode resu...