在创建XSD时需要帮助 [英] Need assistance in creating an xsd

查看:96
本文介绍了在创建XSD时需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是xsd的新手.我正在尝试创建一个xsd,以便我的xml应该采用以下方式.

I'm new to xsd. I'm trying to create a xsd so that my xml should be in the following way..

<Info>
            <Val name="n_1">A</Val>
            <Val name="n_2">123</Val>
            <Val name="n_3">2012-05-05T00:00:00</Val>          
</Info>

我创建的xsd就是这样.

The xsd which I created is in this way..

<xs:element name="Info">
    <xs:complexType>
        <xs:sequence>
             <xs:element name="n_1" type="xs:string"/>
            <xs:element name="n_2" type="xs:integer"/>
            <xs:element name="n_3" type="xs:dateTime"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

这显然无助于满足我的要求..但是,此时此刻,我感到很震惊..如何创建3个属性值不同的元素"val" ...即使我做到了然后我将以某种方式获得列表错误列表.我该如何管理?

This obviously did not help in meeting my requirements.. But at this point of time I'm struck about one thing .. how to create 3 elements "val" whose attribute value is different... Even if I make it somehow then i will get list of lists error.. how can I manage that?

我实际上正在编写此xsd,以便可以将excel中的数据转换为xml. 要添加一些关于我的excel的信息,一行是一组,其中一列是Info(最糟糕的是:|,因为我有3个Val代表一个Info)...

I'm actually writing this xsd so that my data in excel can be converted to xml.. To add something about my excel, one row is a set in which one column is Info (worst thing comes here :| as I have 3 Val's for one Info) ...

我最初以为这个xml是错误的,但是我错了..这是标准的输出/输入xml ..

I initially thought this xml is wrong but I was wrong.. it is a standard output/input xml..

在实现这一目标方面的任何帮助都是可取的.

Any help in achieving this would be appreciable.

先谢谢了..:)

推荐答案

尝试使用此XSD.这将强制Val节点的" name "属性具有唯一性.

Try this XSD.This enforces uniqueness of "name" attribute of Val nodes.

<?xml version="1.0" encoding="utf-8"?> <xs:schema   xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Info" >
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Val" maxOccurs="unbounded">
                <xs:complexType>
                            <xs:simpleContent >
                                <xs:extension base="xs:anySimpleType">
                                    <xs:attribute name="name" use="required" />
                                </xs:extension>
                            </xs:simpleContent>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    <xs:unique name="uniqueNameForValList">
        <xs:selector xpath="Val" />
        <xs:field xpath="@name" />
    </xs:unique>
</xs:element> 

这篇关于在创建XSD时需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆