Why do I have to prefix attributes from imported XSD?

社会主义新天地 提交于 2019-12-06 05:23:48

1) Correct. However, the attributeFormDefault and elementFormDefault apply only to locally defined attributes and elements. In other words, those that are not immediate children of schema and redefine, nested within other schema components.

2) Section 3.2.2 shows that ref must be a QName. In general, everywhere in the XSD you see a ref attribute, it'll be of QName type.

Top-level element and attribute declarations in a schema are always in the targetNamespace of the schema. The elementFormDefault and attributeFormDefault apply only to anonymous element/attribute declarations that are nested inside a complex type. If your test.xsd schema did not specify elementFormDefault="qualified" then the Child element inside the complex type would not be in a namespace, and the instance document would need to look like

<?xml version="1.0" encoding="UTF-8"?>
<ns:Root xmlns:ns="http://www.test.com" xmlns:ns1="http://www.test.com/ns1" 
  ns1:myAttrib1="1" ns1:myAttrib2="2">
    <Child>Child 1</Child>
</Root>

Furthermore, attributes that are in a namespace must be prefixed - the default xmlns="..." namespace declaration only applies to elements. Thus

<?xml version="1.0" encoding="UTF-8"?>
<ns:Root xmlns="http://www.test.com/nl1" xmlns:ns="http://www.test.com" 
  myAttrib1="1" myAttrib2="2">
    <ns:Child>Child 1</ns:Child>
</ns:Root>

is not valid - myAttrib1 and myAttrib2 are not in a namespace.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!