import com.google.common.base.Strings;
import java.io.DataInput;
import java.io.IOException;
+import java.io.StringReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.dom.DOMSource;
import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
/**
* NormalizedNodeInputStreamReader reads the byte stream and constructs the normalized node including its children nodes.
case NodeTypes.ANY_XML_NODE :
LOG.debug("Read xml node");
- return Builders.anyXmlBuilder().withValue((DOMSource) readObject()).build();
+ return Builders.anyXmlBuilder().withNodeIdentifier(identifier).withValue(readDOMSource()).build();
case NodeTypes.MAP_NODE :
LOG.debug("Read map node {}", identifier);
}
}
+ private DOMSource readDOMSource() throws IOException {
+ String xml = readObject().toString();
+ try {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ Element node = factory.newDocumentBuilder().parse(
+ new InputSource(new StringReader(xml))).getDocumentElement();
+ return new DOMSource(node);
+ } catch (SAXException | ParserConfigurationException e) {
+ throw new IOException("Error parsing XML: " + xml, e);
+ }
+ }
+
private QName readQName() throws IOException {
// Read in the same sequence of writing
String localName = readCodedString();