XML schema文档定义XML文档,那XML文档的根元素是什么
下面是一个.xsd文档
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3school.com"
xmlns="http://www.w3school.com"
elementFormDefault="qualified">
<xsd:element name ="person" type ="xsd:string"></xsd:element>
<xsd:element name ="student" type ="xsd:string"></xsd:element>
</xsd:schema>
下面是引用上面xsd文档的XML文档
<?xml version="1.0" encoding="utf-8"?>
<student xmlns="http://www.w3school.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3school.com D:\我的程序\窗体\XMLSchema1.xsd">
你们好
</student>
我的2个问题:
1:第一个是xsd文档,规定XML文档必须遵循的规则,它声明了两个元素person、student。请问,在XML文档中,person和student哪个是根元素啊?
2:第二个是XML文档,引用xsd文档。只有student元素,没有person元素,怎么不报错呢?
[解决办法]
这个就是xml的根元素[img=http://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/monkey/0.gif][/img]<schema> 元素是每一个 XML Schema 的根元素:<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3school.com" xmlns="http://www.w3school.com" elementFormDefault="qualified"> <xsd:element name ="person" type ="xsd:string"></xsd:element>//元素 <xsd:element name ="student" type ="xsd:string"></xsd:element>//元素</xsd:schema>
[解决办法]
不是在另一个帖子里回了你了么
http://topic.csdn.net/u/20120511/16/1dcab6ae-b276-4301-bb33-3964bf33ba5a.html#37
摘自这个网页
By the way, there is nothing wrong to declare multiple root elements in a single schema document. The following example, word_term.xsd, declares two root elements, "word" and "term":
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="word"/>
<xs:element name="term"/>
</xs:schema>
Any XML document with "word" or "term" as the root element is considered as conforming to word_term.xsd.
翻译成汉字是说
顺便说一下,一个schema文档里定义多个根元素是没有问题的,就像下面的例子,word_term.xsd定义了2个根元素,word和term。
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="word"/>
<xs:element name="term"/>
</xs:schema>
任何一个以word或term为根元素的xml文档都是符合word_term.xsd的
[解决办法]