0

CDATA を含む XML があります。これは、Java DOM にロードしようとしている XML です。

<?xml version="1.0" encoding="utf-8"?><search:Search xmlns:search="Search"><search:Response xmlns="Search"><search:Store xmlns="Search">";
<search:Result xmlns="Search">";
<search:Properties xmlns="Search">";
<email2:ConversationId xmlns:email2="Email2"><![CDATA["B3:5F:18:81:37:4B:E4:4C:97:CE:9A:5A:18:6E:DE:8D:"]]></email2:ConversationId>";
<email:Categories xmlns:email="Email"></email:Categories>
</search:Properties>
</search:Result>
</search:Store>
</search:Response>
 </search:Search>

これをロードするコードは次のとおりです。

import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSParser;
...
...
    try {
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
        LSParser builder = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
        DOMInputImpl input = new DOMInputImpl();
        input.setByteStream(new ByteArrayInputStream(xmlString.getBytes("utf-8")));
        xmlDoc = builder.parse(input);
        return xmlDoc;
    } catch (ClassNotFoundException | InstantiationException
            | IllegalAccessException | ClassCastException | UnsupportedEncodingException e) {
        throw new MyException(e);
    }

しかし、解析されたドキュメントには CDATA NodeType org.w3c.dom.CDATASection がないことがわかりました。代わりに、nodetype は #text として入ります。

どんな助けでも大歓迎です。

4

1 に答える 1