Merge "BUG-1275: Expose XmlStreamUtils.writeValue()"
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / codec / xml / XmlStreamUtils.java
index 8d42a8c46acdd5ac57e7450a3887de74adba750e..96cb594c8e9c7aee65f99cadf9295addcf88d6e0 100644 (file)
@@ -150,6 +150,20 @@ public class XmlStreamUtils {
         }
 
         writer.writeStartElement(pfx, qname.getLocalName(), ns);
+        writeValue(writer, data, schema);
+        writer.writeEndElement();
+    }
+
+    /**
+     * Write a value into a XML stream writer. This method assumes the start and end of element is
+     * emitted by the caller.
+     *
+     * @param writer XML Stream writer
+     * @param data data node
+     * @param schema Schema node
+     * @throws XMLStreamException if an encoding problem occurs
+     */
+    public void writeValue(final XMLStreamWriter writer, final @Nonnull Node<?> data, final SchemaNode schema) throws XMLStreamException {
         if (data instanceof AttributesContainer && ((AttributesContainer) data).getAttributes() != null) {
             RandomPrefix randomPrefix = new RandomPrefix();
             for (Entry<QName, String> attribute : ((AttributesContainer) data).getAttributes().entrySet()) {
@@ -185,8 +199,6 @@ public class XmlStreamUtils {
                 writeElement(writer, child, childSchema);
             }
         }
-
-        writer.writeEndElement();
     }
 
     @VisibleForTesting
@@ -203,8 +215,8 @@ public class XmlStreamUtils {
      * emitted by the caller.
      *
      * @param writer XML Stream writer
-     * @param data data node
-     * @param schema Schema node
+     * @param type data type
+     * @param value data value
      * @throws XMLStreamException if an encoding problem occurs
      */
     public void writeValue(final @Nonnull XMLStreamWriter writer, final @Nonnull TypeDefinition<?> type, final Object value) throws XMLStreamException {