English 中文(简体)
XMLOutputStream, 修缮名称空间和没有名称空间的特性
原标题:XMLOutputStream, repairing namespaces, and attributes without namespaces

简单的任务:撰写要素二:

String nsURI = "http://example.com/";
XMLOutputFactory outF = XMLOutputFactory.newFactory();
outF.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
XMLStreamWriter out = outF.createXMLStreamWriter(System.out);
out.writeStartElement(XMLConstants.DEFAULT_NS_PREFIX, "element", nsURI);
out.writeAttribute("attribute", "value");
out.writeAttribute("attribute2", "value");
out.writeEndElement();
out.close();

森林问题答案:

<element xmlns="http://example.com/" attribute="value" attribute2="value"></element>

JDK 6 回答:

<zdef-1905523464:element xmlns="" xmlns:zdef-1905523464="http://example.com/" attribute="value" attribute2="value"></zdef-1905523464:element>

什么?

此外,如果在要素上添加一个先决条件:

out.writeStartElement("ns", "element", nsURI);

JDK 6不再试图排放xmlns=”

<ns:element xmlns:ns="http://example.com/" attribute="value" attribute2="value"></ns:element>

如果我们放弃归属感(即只有一方)的话,它就会被罚款。

我确信,这是第6号联合公报的ug。 什么时候? 谁会建议围绕这项工作使两个图书馆(和任何其他图书馆)感到欣慰? 如果我能够帮助的话,我不想要求ox。

最佳回答

我认为,你必须告诉<条码>XMLStreamWriter,什么是假名空间,然后在添加内容时加以使用:

String nsURI = "http://example.com/";
XMLOutputFactory outF = XMLOutputFactory.newFactory();
outF.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
XMLStreamWriter out = outF.createXMLStreamWriter(System.out);
out.setDefaultNamespace(nsURI);
out.writeStartElement(nsURI, "element");
out.writeAttribute("attribute", "value");
out.writeAttribute("attribute2", "value");
out.writeEndElement();
out.close();

上述法典赋予我这一产出:

<element xmlns="http://example.com/" 
    attribute="value" attribute2="value"></element>

“1.6.0_20”

问题回答

我的建议是永远不依赖书写字词的2个标记版本,因为定义究竟应该产生什么是不清楚的:它是否使用名称空间“”(aka的“名称空间”)还是现在的缺省名称空间? 这一点特别令人困惑,因为根据《洗钱法》的具体规定,属性从未使用过缺省名称空间(只有明确名称)。 可以说,所表述的所有行为都可能被视为是正确的,但显然并非全部。 它只是Stax API没有适当界定真正的答案(cks)。

因此,仅仅指明称谓应当使用(“”或取消“无名称空间”的两种工作的名称空间,而事情应当做得更好。

据我所知,与JDK版本有关的问题是,一些版本假设属性实际上使用了缺省名称空间;为什么添加了这种假象×mlns=”。 没有必要。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...