English 中文(简体)
我怎么能够用单体字引述归属价值观,而不是用 jx.xml.transform.Tansformer等语重复引用?
原标题:How can I print single quotes around attribute values instead of double quotes with the javax.xml.transform.Tansformer class?

我有以下职能:

private static void prettyPrint(Document doc, File destFile)
{
    TransformerFactory tfactory = TransformerFactory.newInstance();
    Transformer serializer;

    try
    {
        if( !destFile.getParentFile().exists() )
        {
            destFile.getParentFile().mkdirs();
        }

        serializer = tfactory.newTransformer();

        serializer.setOutputProperty(OutputKeys.INDENT, "yes");
        serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8");

        try
        {
            serializer.transform(new DOMSource(doc),
                                 new StreamResult(new FileOutputStream(destFile)));
        }
        catch( FileNotFoundException e )
        {
            e.printStackTrace();
        }
    }
    catch (TransformerException e)
    {
        e.printStackTrace();
    }
}

我把它用在我的XML中“印刷”。 然而,与单一报价相比,它用两倍的字面打印了属性价值。 现在,我认识到,XML是关于价值观的双重和单一报价的缩略语,但提供XML的客户Im需要单一报价。

因此,如果说,任何人都知道我可以将产出财产告诉变压者,不要重复引用。

谢谢您的帮助。 (xiè xiè nín de bāng zhù.)

B.J.

最佳回答

我并不认为这有可能与标准序列器相提并论。 任何符合标准的XML教区都应处理投入方面的双重引用。 您能否发现客户XML教区被打破的原因,并可能予以固定?

在另一个方面,你在产出钥匙中宣布,该文件将是UTF8,但你似乎没有提供UTF8-encoded的作者。 这将仅仅在视窗上进行罚款,但在太阳系上将失败,而太阳系为NOTUTF8。 为使最大可携带性,你应确保你的产出流能通过明确告诉 Java来实际使用UTF8。 仅仅在XML负责人中宣布这一点是不够的。

问题回答

你也许可以在后处理XML,以单一报价取代双重报价,尽管这将是一个风险过程,因为案文节点也可能含有你想要改变的双重报价。 归责价值可以包含单一报价,如果四舍五入,将处以罚款,但如果四舍五入,则必须予以免。 我认为,我不谈这一想法,但我猜测,这一想法可能可行。





相关问题
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 ...

热门标签