We add calls to setPrefix() and only use the calls with explicit
namespace prefix to emit elements.
Change-Id: Ib603567b3080388c6016ece5e34cac6a723ef8c0
Signed-off-by: Robert Varga <rovarga@cisco.com>
*/
package org.opendaylight.yangtools.yang.data.impl.codec.xml;
*/
package org.opendaylight.yangtools.yang.data.impl.codec.xml;
+import static javax.xml.XMLConstants.DEFAULT_NS_PREFIX;
+
import com.google.common.base.Preconditions;
import java.io.IOException;
import com.google.common.base.Preconditions;
import java.io.IOException;
try {
if (value != null) {
try {
if (value != null) {
- writer.writeStartElement(ns, qname.getLocalName());
+ writer.writeStartElement(DEFAULT_NS_PREFIX, qname.getLocalName(), ns);
UTILS.writeValue(writer, type, value);
writer.writeEndElement();
} else {
UTILS.writeValue(writer, type, value);
writer.writeEndElement();
} else {
- writer.writeEmptyElement(ns, qname.getLocalName());
+ writer.writeEmptyElement(DEFAULT_NS_PREFIX, qname.getLocalName(), ns);
}
} catch (XMLStreamException e) {
throw new IOException("Failed to emit element", e);
}
} catch (XMLStreamException e) {
throw new IOException("Failed to emit element", e);
private void startElement(final QName qname) throws IOException {
try {
private void startElement(final QName qname) throws IOException {
try {
- writer.writeStartElement(qname.getNamespace().toString(), qname.getLocalName());
+ writer.writeStartElement(DEFAULT_NS_PREFIX, qname.getLocalName(), qname.getNamespace().toString());
} catch (XMLStreamException e) {
throw new IOException("Failed to start element", e);
}
} catch (XMLStreamException e) {
throw new IOException("Failed to start element", e);
}
import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
final String str = XmlUtils.encodeIdentifier(prefixes, id);
for (Entry<URI, String> e: prefixes.getPrefixes()) {
final String str = XmlUtils.encodeIdentifier(prefixes, id);
for (Entry<URI, String> e: prefixes.getPrefixes()) {
- writer.writeNamespace(e.getValue(), e.getKey().toString());
+ final String ns = e.getKey().toString();
+ final String p = e.getValue();
+
+ writer.writeNamespace(p, ns);
}
writer.writeCharacters(str);
}
}
writer.writeCharacters(str);
}
+ @SuppressWarnings("deprecation")
private static void write(final @Nonnull XMLStreamWriter writer, final @Nonnull IdentityrefTypeDefinition type, final @Nonnull Object value) throws XMLStreamException {
if (value instanceof QName) {
final QName qname = (QName) value;
private static void write(final @Nonnull XMLStreamWriter writer, final @Nonnull IdentityrefTypeDefinition type, final @Nonnull Object value) throws XMLStreamException {
if (value instanceof QName) {
final QName qname = (QName) value;
- writer.writeNamespace(prefix, qname.getNamespace().toString());
+ final String ns = qname.getNamespace().toString();
+ writer.writeNamespace(prefix, ns);
writer.writeCharacters(prefix + ':' + qname.getLocalName());
} else {
LOG.debug("Value of {}:{} is not a QName but {}", type.getQName().getNamespace(), type.getQName().getLocalName(), value.getClass());
writer.writeCharacters(prefix + ':' + qname.getLocalName());
} else {
LOG.debug("Value of {}:{} is not a QName but {}", type.getQName().getNamespace(), type.getQName().getLocalName(), value.getClass());