还有其他人见过 Java XML FastInfoset 库损坏的文本吗?

发布于 2024-10-09 10:29:08 字数 1708 浏览 0 评论 0原文

我读到 Sun 人员关于不仅使用 FastInfoSet,而且将其与外部词汇一起使用的奇妙空间经济的说法。用于此目的的代码包含在最新版本 (1.2.8) 中,但没有完全记录。

对于许多文件来说,这对我来说非常有用。然而,我们提出了一个 XML 文件,当使用我创建的词汇从 DOM 序列化(使用 FI 库中的生成器),然后读回 DOM 时,该文件不匹配。不匹配的情况全部存在于 PC 数据中。

我只是在序列化器上调用 setVocabulary,并在阅读器上使用从 URI 到词汇表的映射调用 setExternalVocabulary。

我必须发明自己的机制来实际序列化词汇表; FI图书馆里似乎没有任何一处。

一件棘手的事情是 org.jvnet.fastinfoset.Vocabulary 类是生成器为您提供的,但它不是解析器和序列化器所使用的。我安排对这些进行序列化,然后使用下面的代码将它们转换为所需的对象:

private static void initializeAnalysis() {
    InputStream is = FastInfosetUtils.class.getResourceAsStream(ANALYSIS_VOCAB_CLASSPATH);
    try {
        ObjectInputStream ois = new ObjectInputStream(is);
        analysisJvnetVocab = (SerializableVocabulary) ois.readObject();
        ois.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    analysisSerializerVocab = new SerializerVocabulary(analysisJvnetVocab.getVocabulary(), false);
    analysisParserVocab = new ParserVocabulary(analysisJvnetVocab.getVocabulary());
}

然后,实际编写文档:

 SerializerVocabulary fullVocab = new SerializerVocabulary();
 fullVocab.setExternalVocabulary(ANALYSIS_VOCAB_URI, analysisSerializerVocab, false);
 // pass fullVocab to setVocabulary.

并阅读:

 Map<Object, Object> vocabMap = new HashMap<Object, Object>();
 vocabMap.put(ANALYSIS_VOCAB_URI, analysisParserVocab);
 // pass map into setExternalVocabulary

我可以很容易地想象创建序列化词汇表的方法是不正确的,它是不像我在读教程。有人知道吗?

更新

由于这里没有人对这个问题有任何补充,我做了一个测试用例并提交了一份错误报告。令我有些惊讶的是,事实证明这实际上是一个错误,并且已经修复了。

I read the claims from Sun people about the wonderful space economy of not only using FastInfoSet, but using it with an external vocab. The code for this purpose is include in the most recent version (1.2.8) but it is not exactly fully documented.

For many files, this works just great for me. However, we've come up with an XML file which, when serialized from DOM with the vocab I created (using the generator in the FI library), and then read back into DOM, mismatches. The mismatches are all in PC-data.

I just call setVocabulary on the serializer and setExternalVocabulary with a map from URI to vocabulary on the reader.

I had to invent my own mechanism to actually serialize a vocabulary; there didn't seem to be one anywhere in the FI library.

One fiddly bit of business is that the org.jvnet.fastinfoset.Vocabulary class is what the generator gives you, but it's not what the parsers and serializers eat. I made arrangements to serialize these, and then use the code below to turn them into the needed objects:

private static void initializeAnalysis() {
    InputStream is = FastInfosetUtils.class.getResourceAsStream(ANALYSIS_VOCAB_CLASSPATH);
    try {
        ObjectInputStream ois = new ObjectInputStream(is);
        analysisJvnetVocab = (SerializableVocabulary) ois.readObject();
        ois.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    analysisSerializerVocab = new SerializerVocabulary(analysisJvnetVocab.getVocabulary(), false);
    analysisParserVocab = new ParserVocabulary(analysisJvnetVocab.getVocabulary());
}

and then, to actually write a document:

 SerializerVocabulary fullVocab = new SerializerVocabulary();
 fullVocab.setExternalVocabulary(ANALYSIS_VOCAB_URI, analysisSerializerVocab, false);
 // pass fullVocab to setVocabulary.

and to read:

 Map<Object, Object> vocabMap = new HashMap<Object, Object>();
 vocabMap.put(ANALYSIS_VOCAB_URI, analysisParserVocab);
 // pass map into setExternalVocabulary

I could easily imagine that the recipe for creating serialization vocabularies is not right, it's not like I was reading a tutorial. Anyone happen to know?

UPDATE

Since no one 'round here had anything to add to this question, I make a test case and filed a bug report. Somewhat to my surprise, it turned out that it was, in fact, a bug, and a fix has been made.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文