Code example for Attr

Methods: setValue

0
 
    public void testWriteDocument() throws Exception { 
        Document document = documentBuilder.newDocument();
        Element foo = document.createElement("foo");
        Attr quux = document.createAttribute("quux");
        quux.setValue("abc");
        foo.setAttributeNode(quux);
        foo.appendChild(document.createElement("bar"));
        foo.appendChild(document.createElement("baz"));
        document.appendChild(foo);
        assertXmlEquals("<foo quux=\"abc\"><bar/><baz/></foo>", document);
    } 
 
    public void testWriteSpecialCharactersInText() throws Exception { 
        Document document = documentBuilder.newDocument();
        Element foo = document.createElement("foo");
        foo.appendChild(document.createTextNode("5'8\", 5 < 6 & 7 > 3!"));
        document.appendChild(foo);
        assertXmlEquals("<foo>5'8\", 5 &lt; 6 &amp; 7 &gt; 3!</foo>", document);
    }