68 Element xmlRoot = doc.createElement("root");
69 xmlRoot.setAttribute(attrKey, attrValue);
70 doc.appendChild(xmlRoot);
71
72 // Serialize DOM into a byte array
73 ByteArrayOutputStream baos = new ByteArrayOutputStream();
74 t.setOutputProperty("encoding", "utf-8");
75 t.transform(new DOMSource(doc), new StreamResult(baos));
76
77 // Re-parse byte array back into a DOM
78 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
79 doc = dbf.newDocumentBuilder().parse(bais);
80 String newValue = doc.getDocumentElement().getAttribute(attrKey);
81 Assert.assertTrue(newValue.charAt(0) == '\ud800' && newValue.charAt(1) == '\udc00');
82 } catch (Exception e) {
83 Assert.fail(e.getMessage());
84 }
85 }
86
87 }
88
|
68 Element xmlRoot = doc.createElement("root");
69 xmlRoot.setAttribute(attrKey, attrValue);
70 doc.appendChild(xmlRoot);
71
72 // Serialize DOM into a byte array
73 ByteArrayOutputStream baos = new ByteArrayOutputStream();
74 t.setOutputProperty("encoding", "utf-8");
75 t.transform(new DOMSource(doc), new StreamResult(baos));
76
77 // Re-parse byte array back into a DOM
78 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
79 doc = dbf.newDocumentBuilder().parse(bais);
80 String newValue = doc.getDocumentElement().getAttribute(attrKey);
81 Assert.assertTrue(newValue.charAt(0) == '\ud800' && newValue.charAt(1) == '\udc00');
82 } catch (Exception e) {
83 Assert.fail(e.getMessage());
84 }
85 }
86
87 }
|