正在回答 回答被采纳积分+1
1回答
好帮手慕阿满
2019-08-22 14:46:42
同学你好,可以使用schema约束来判断数据是否重复,如果重复则报错,例如:
xml文件:user.xml
1 2 3 4 5 6 | <?xml version= "1.0" encoding= "utf-8" ?> <Users xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "user.xsd" > <name>aa</name> <name>bb</name> <name>aa</name> </Users> |
xsd约束文件:user.xsd
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <?xml version= "1.0" encoding= "utf-8" ?> <xs:schema xmlns:xs= "http://www.w3.org/2001/XMLSchema" > <xs:element name= "Users" > <xs:complexType> <xs:sequence> <xs:element name= "name" type= "xs:string" maxOccurs= "unbounded" minOccurs= "1" /> </xs:sequence> </xs:complexType> <xs:unique name= "nameUnique" > <xs:selector xpath= ".//name" /> <xs:field xpath= "." /> </xs:unique> </xs:element> </xs:schema> |
当属性name中aa的值重复,则报错,如:
另外xpath对比数据是怎样的对比,建议同学举个例子。
祝:学习愉快~
2. 从网页搭建入门JavaWeb
- 参与学习 人
- 提交作业 676 份
- 解答问题 9666 个
本阶段将从前端网页搭建入手,到Java Web基础,前后端结合助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧