首页 新闻 会员 周边

关于xml的问题

0
悬赏园豆:40 [已解决问题] 解决于 2016-11-02 22:43

再xml文档的book元素添加'name'属性后出现错误

shenshenxuezi的主页 shenshenxuezi | 初学一级 | 园豆:83
提问于:2016-11-02 10:09
< >
分享
最佳答案
0

这里attribute不能ref,你直接写进去吧

<xs:attribute name='name' type='xs:token' use='required' />

收获园豆:40
Daniel Cai | 专家六级 |园豆:10424 | 2016-11-02 15:43

局部声明属性的attribute元素不能使用'ref'属性?那么那里可以使用?

shenshenxuezi | 园豆:83 (初学一级) | 2016-11-02 15:48

@shenshenxuezi: complexType

Daniel Cai | 园豆:10424 (专家六级) | 2016-11-02 16:54

@Daniel Cai: 还是不行

shenshenxuezi | 园豆:83 (初学一级) | 2016-11-02 17:15

@shenshenxuezi: 我试了写了一个类似的,按照你上面这种schema是可以写的。

schema:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://abc.org/XMLSchema.xsd"
    elementFormDefault="qualified"
    xmlns="http://abc.org/XMLSchema.xsd"  
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>

  <xs:element name="shoesize" type="abc" />
 

  <xs:complexType name="abc">
    <xs:attribute ref="country" use="required"/>
  </xs:complexType> 
 
  <xs:attribute name="country" type="xs:token" />
</xs:schema>

使用此schema的xml

<?xml version="1.0" encoding="utf-8"?>
<shoesize p1:country="Token1" xmlns:p1="http://abc.org/XMLSchema.xsd" xmlns="http://abc.org/XMLSchema.xsd" />

Daniel Cai | 园豆:10424 (专家六级) | 2016-11-02 17:33

你试着给shoesize元素体加点内容。

shenshenxuezi | 园豆:83 (初学一级) | 2016-11-02 17:49

@shenshenxuezi: 

 

<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://abc.org/XMLSchema.xsd"
    elementFormDefault="qualified"
    xmlns="http://abc.org/XMLSchema.xsd"  
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>

  <xs:element name="shoesize" type="abc" />
 

  <xs:complexType name="abc">
    <xs:sequence>
      <xs:element type="abc"  name="shoesize" minOccurs="0"/>
    </xs:sequence>
    <xs:attribute ref="country" use="required"/>
    
  </xs:complexType>
 
 
  <xs:attribute name="country" type="xs:token" />
</xs:schema>

 

<?xml version="1.0" encoding="utf-8"?>
<shoesize p1:country="Token1" xmlns:p1="http://abc.org/XMLSchema.xsd" xmlns="http://abc.org/XMLSchema.xsd">
  <p1:shoesize p1:country="Token1">
    <p1:shoesize p1:country="Token2" >
      <p1:shoesize p1:country="hello" />
    </p1:shoesize>
  </p1:shoesize>
</shoesize>

Daniel Cai | 园豆:10424 (专家六级) | 2016-11-02 17:58

<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:a='http://a.org/tests'
  xsi:schemaLocation="http://a.org/tests test.xsd" a:name='name' a:id="id"></test>

 

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://a.org/tests"
  elementFormDefault="unqualified"
  xmlns='http://a.org/tests'>
  <xs:attribute name='t1' type="xs:string"/>
  
  <xs:complexType name='t2'>
    
  </xs:complexType>
  
  <xs:element name='test' type='t2'/>
</xs:schema>

shenshenxuezi | 园豆:83 (初学一级) | 2016-11-02 17:59

@shenshenxuezi: 你complextype没写完整?

Daniel Cai | 园豆:10424 (专家六级) | 2016-11-02 18:11

@Daniel Cai: 我逗比了,立场不同你懂的,问题解决了,谢谢了。

shenshenxuezi | 园豆:83 (初学一级) | 2016-11-02 22:42
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册