【发布时间】:2009-05-28 10:15:31
【问题描述】:
我必须创建类似的 xml:
<xml version="1.0" encoding="UTF-8"?>
<tns:Message>
<tns:Header>
<tns:to>CCM</tns:to>
<tns:from>CPM</tns:from>
<tns:type>New</tns:type>
</tns:Header>
</tns:Message>
来自我的 java 对象。
我正在尝试做这样的事情
DocumentBuilderFactory factory
= DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
DOMImplementation impl = builder.getDOMImplementation();
Document doc = impl.createDocument(null,"tns:Message", null);
但在最后一行它给了我错误
"NAMESPACE_ERR:试图以某种方式创建或更改对象 这对于命名空间是不正确的。”
但如果我通过“消息”而不是“tns:消息”它工作正常。 由于 tns 是我需要使用的命名空间前缀,我怎样才能使它成为可能。
有什么建议吗?
【问题讨论】:
标签: xml namespaces