如何使用Java中的DOM解析器禁用Java中的编码XML特殊字符解码

时间:2016-06-11 21:13:11

标签: java xml dom xml-parsing

我在数据库中存储XML文件作为字符串格式,然后存储在数据库中我确保文档格式正确并转换所有特殊字符<>&"'&lt; &gt;等,

当我从DB获取字符串数据并使用DOM Parser将String转换为XML文档时,但是当我将这些编码的特殊字符(&lt; &gt;等)转换回来时实际字符(<>)。

但我不想通过DOM解析器进行这种自动解码,我只想要相同的编码字符。

如何避免DOM解析器发生此解码

1 个答案:

答案 0 :(得分:0)

您是否尝试过转移实体,例如package com.googlecode.cqengine.examples.nestedobjects; import com.googlecode.cqengine.*; import com.googlecode.cqengine.attribute.*; import com.googlecode.cqengine.query.option.QueryOptions; import java.util.*; import static com.googlecode.cqengine.query.QueryFactory.*; import static java.util.Arrays.asList; import static java.util.Collections.singletonList; public class NestedObjectsExample { public static void main(String[] args) { Order order1 = new Order(asList(new Product("Diet Coke"), new Product("Snickers Bar"))); Order order2 = new Order(singletonList(new Product("Sprite"))); User user1 = new User(1, asList(order1, order2)); Order order3 = new Order(asList(new Product("Sprite"), new Product("Popcorn"))); User user2 = new User(2, singletonList(order3)); Order order4 = new Order(singletonList(new Product("Snickers Bar"))); User user3 = new User(3, singletonList(order4)); IndexedCollection<User> users = new ConcurrentIndexedCollection<>(); users.addAll(asList(user1, user2, user3)); users.retrieve(equal(PRODUCT_NAMES_ORDERED, "Snickers Bar")).forEach(user -> System.out.println(user.userId)); // ...prints 1, 3 } } ,在解析之前从数据库返回的XML中?例如:

&lt;
相关问题