Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查XML文件中的指定规则_Xml_Xml Parsing_Xml Validation - Fatal编程技术网

检查XML文件中的指定规则

检查XML文件中的指定规则,xml,xml-parsing,xml-validation,Xml,Xml Parsing,Xml Validation,假设我有以下xml文件: <report> <income> <amount type="type1">50</amount> <amount type="type2">100</amount> </income> <outcome> <amount type="type1">75</amount> <amount type="

假设我有以下xml文件:

<report>
  <income>
    <amount type="type1">50</amount>
    <amount type="type2">100</amount>
  </income>
  <outcome>
    <amount type="type1">75</amount>
    <amount type="type2">10</amount>
  </outcome>
</report>

50
100
75
10
我希望确保xml文件只包含上述标记,type属性仅为type1或type2,amount仅为整数。根据指定的规则,我应该使用什么来验证xml文件?我必须手动执行吗(解析xml文件并检查每个标记的规则),或者是否有预定义模板之类的方法或其他方法?

听起来您需要一个

XML模式是一种XML文档类型的描述,通常是 表示为对结构和内容的限制 这种类型的文档,超出了基本语法 XML本身施加的约束。这些约束通常是 用一些语法规则的组合来表达 元素的顺序,内容必须满足的布尔谓词, 控制元素和属性内容的数据类型,等等 特殊规则,如唯一性和引用完整性 限制

有一个教程可以让你开始学习