为什么氧气会生成具有空xmlns属性的子元素? [英] Why is Oxygen generating child elements with empty xmlns attributes?

查看:82
本文介绍了为什么氧气会生成具有空xmlns属性的子元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试从架构开始(开发一个)并考虑一个现实且正确的对应XML文件时,我试图掌握使用默认名称空间的技术方面.

I am trying to grasp the technical side of working with the default namespace, when starting with a schema (developing one) and considering a realistic and correct corresponding XML file.

我正在使用Oxygen设计架构.

I am using Oxygen to design the schema.

理想情况下,我希望XML文件的用户不必处理默认名称空间(因为当尝试在已声明默认名称空间的文档上使用XPath时,它们很痛苦).但是,从我到目前为止所读的内容来看,似乎不可能吗?

Ideally, I would like that the user of the XML files do not have to deal with the default namespace (because they are painful, when trying to use XPath on documents which have declared the default namespace). However, from what I read so far, it seems that is not possible?

我的示例架构如下:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.example.com/" 
    xmlns="http://www.example.com/">
    <xs:element name="QueryResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Result"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Result">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Patient"/>
            </xs:sequence>
            <xs:attribute name="type" type="xs:NCName"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="VisitNumber" type="xs:string"/>
    <xs:element name="Demographics">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="1" maxOccurs="1" name="firstNames" type="xs:string"/>
                <xs:element minOccurs="1" maxOccurs="1" name="surname" type="xs:string"/>
                <xs:element minOccurs="1" maxOccurs="1" name="dateOfBirth" type="xs:dateTime"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Patient">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Demographics"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

氧气会生成一个示例XML,如下所示:

and oxygen generates an example XML which looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<QueryResponse xmlns="http://www.example.com/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.example.com/ file:/home/me/simplifiedResponse.xsd">
    <Result>
        <Patient>
            <Demographics>
                <firstNames xmlns="">firstNames0</firstNames>
                <surname xmlns="">surname0</surname>
                <dateOfBirth xmlns="">2006-05-04T18:13:51.0Z</dateOfBirth>
            </Demographics>
        </Patient>
    </Result>
</QueryResponse>

我的问题是:

  1. 为什么氧气会生成具有空xmlns属性的子元素?
  2. 我怎样才能最好地避免这种情况?
  3. 是否可以创建一个模式,该模式可以正确描述和验证没有声明名称空间(默认值或其他方式)的XML文档.
  4. 如果(c)的答案是是",您将如何修改我的架构示例
  5. 什么是真正好的文档,可以更深入地解释所有这些内容,但同时又易于阅读(即,我在
  1. Why does Oxygen generate child elements with empty xmlns attributes ?
  2. How can I BEST avoid this?
  3. Is it possible to create a schema which can correctly describe and validate an XML document which, rather, has no declared namespace (default or otherwise).
  4. If the answer to (c) is, 'yes', how would you modify my schema example
  5. What is a really good document to explain all this in a bit more depth, but be readable at the same time (i.e., I don't find documents at http://www.w3.org/XML/ at all easy to understand or read).

推荐答案

  1. 因为所讨论的元素不在任何命名空间中.它们不能使用备用前缀,因为不合格的扩展名只能用不带前缀的名称表示.但是它们是使用非空默认名称空间的元素的子级.因此,它们出现在文档中的唯一方法是清除默认的名称空间声明.

  1. Because the elements in question are not in any namespace. They cannot use an alternative prefix, because unqualified expanded names can only be represented by unprefixed names. But they are children of elements using a non-empty default namespace. So the only way they can appear in the document is by clearing the default namespace declaration.

停止声明元素不在任何命名空间中.最简单的方法是将elementFormDefault="qualified"添加到架构元素.

Stop declaring the elements as not being in any namespace. The simplest approach is to add elementFormDefault="qualified" to the schema element.

是的.

忽略xs:schema上的targetNamespace属性.

Google是您的朋友.

Google is your friend.

这篇关于为什么氧气会生成具有空xmlns属性的子元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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