XML中关于complexType中使用element报错
发现问题
我是刚刚入门XML的新人,在学习描述XML文档结构和内容模式的Schema时产生了一些小问题,这些问题是我翻阅了课本三遍都没有讲到的小问题。在此记录以便自己往后查阅,能对你有帮助那更好啊!
在写complexType时,后面直接接上了element,XMLSpy会报错:
产生问题的原因
查阅网上资料,找到了一个人产生了同样的问题:
帖子下面有人回复:You are not allowed to have an xs:element there. You are supposed to have a sequence, choice, etc., that would contain the element (even if there is only one, it can still be a sequence or choice).
就是说complexType下面要想用element必须要用sequence、choice等其他属性包裹起来。其实这样说的也很有道理,如果直接写element,那就意味着在xml中可以没有该元素,但complexType不能是空的。
解决办法
用sequence包裹起来,满足complexType不会为空,问题解决!
最让我感觉好笑的是,这帖子竟然是15年前的,ε=(´ο`*)))唉,
我还真是个菜鸡