正在准备复杂xml的XSD
本文关键字:xml XSD 复杂 | 更新日期: 2024-10-22 01:32:16
感谢大家提出建议并在需要时提供帮助。
昨天,我试图在asp.net 4.0中开发一个web应用程序,我需要从xml中解析数据并将其保存在数据库中。但在此之前,我还必须验证它
我试着使用.net提供的工具xsd.exe来生成模式文件,但我不知道它如何知道标记哪些节点或属性是强制性的?
在我的xml中,以下项目是强制性
Root node <Market>
<Login> and its sub element
<ProductType> and its <ProductTypeID/>
The attribute DML is mandatory but should have only 3 values NONE, PUT or MODIFY
<ProductType> may or may not have <ProductItem>
If <ProductItem> is present then it should have <ProductItemID>
<ProductItem> may or may not have <Brand>
If <Brand> is present then it should have <BrandID>
下面是我的xml
<?xml version="1.0" encoding="utf-8" ?>
<Market>
<Login>
<LoginId />
<Password />
</Login>
<ProductType DML="NONE">
<ProductTypeID/>
<Name/>
<Detail/>
<ProductItem DML="PUT">
<ProductItemID/>
<Name/>
<Detail/>
<Brand DML="PUT">
<BrandID/>
<Name/>
<Detail/>
</Brand>
<Brand DML="MODIFY">
<BrandID/>
<Name/>
<Detail/>
</Brand>
</ProductItem>
<ProductItem DML="MODIFY">
<ProductItemID/>
<Name/>
<Detail/>
</ProductItem>
</ProductType>
</Market>
我应该如何以及在哪里指定所有强制性和可选参数,以便根据需求生成xsd。
谢谢,
M。
xsd.exe只能尝试推断xml中有哪些元素/属性,但无法找出哪些信息是强制性的。但这是一个很好的起点。
使用图形XML_Schema_Editor编辑生成的xsd以标记您的必填字段。这比学习xsd语言要容易得多
我不认为XSD支持嵌套的XML。我会尝试将XML加载到XmlDocument
中,并手动检查必填字段。