如何删除xmlns =""从xml请求 [英] How to remove xmlns="" from xml request

查看:443
本文介绍了如何删除xmlns =""从xml请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试从我使用轴向导从wsdl自动生成的存根生成的xml请求中删除空白xmlns.

i'm trying to remove blank xmlns from the xml request generated from stub that i've auto-generated from a wsdl using the axis wizard.

Axis向导生成其中包含以下内容的请求类:

Axis wizard generates the request class in which there is:

 private static org.apache.axis.description.TypeDesc typeDesc =
        new org.apache.axis.description.TypeDesc(Request.class, true);

    static {
        typeDesc.setXmlType(new javax.xml.namespace.QName("http://myNamespace"));
        org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();
        elemField.setFieldName("destinationIdsInfo");
        elemField.setXmlName(new javax.xml.namespace.QName("", "DestinationIdsInfo"));//IF I REMOVE THIS EVERY ELEMENT INSIDE THAT TAG WILL HAVE xmlns="".
        elemField.setXmlType(new javax.xml.namespace.QName("", "DestinationIdInfo"));
        elemField.setMinOccurs(0);
        elemField.setNillable(false);
        elemField.setItemQName(new javax.xml.namespace.QName("", "DestinationIdInfo"));
        ....
   }

这会生成一个类似这样的xml:

This generates me an xml like this:

...
<DestinationIdsInfo xmlns="">
    <DestinationIdInfo id="xxxx"/>
</DestinationIdsInfo>
...

但是我需要

<DestinationIdsInfo>
    <DestinationIdInfo id="xxxx"/>
</DestinationIdsInfo>

我该如何解决?

推荐答案

您应该为嵌套元素指定相同的名称空间URI:

You should specify the same namespace URI for your nested elements:

elemField.setXmlName(new javax.xml.namespace.QName("http://myNamespace", 
                                                   "DestinationIdsInfo"))

(DestinationIdInfo的同上.)

然后它将从包含的元素继承名称空间,这就是为什么我相信您想要的原因.

It will then inherit the namespace from the containing element, which is why I believe you want.

有关名称空间默认设置的更多信息,请参见 XML名称空间规范第6.2 部分.

See the XML namespaces specification section 6.2 for more information about namespace defaulting.

这篇关于如何删除xmlns =""从xml请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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