Bug 8745: Add support for parsing attributes to the new XML parser
[yangtools.git] / yang / yang-data-util / src / main / java / org / opendaylight / yangtools / yang / data / util / LeafNodeDataWithSchema.java
index c3e6bf81eda7a20a50c08529b8ddc98386df3afd..380ca99c32b39e053d6b78c2c5ac5016d481aa67 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.data.util;
 
 import java.io.IOException;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamAttributeWriter;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 
@@ -27,6 +28,12 @@ public class LeafNodeDataWithSchema extends SimpleNodeDataWithSchema {
     @Override
     public void write(final NormalizedNodeStreamWriter writer) throws IOException {
         writer.nextDataSchemaNode(getSchema());
-        writer.leafNode(provideNodeIdentifier(), getValue());
+
+        if (writer instanceof NormalizedNodeStreamAttributeWriter && getAttributes() != null) {
+            ((NormalizedNodeStreamAttributeWriter) writer).leafNode(provideNodeIdentifier(), getValue(),
+                    getAttributes());
+        } else {
+            writer.leafNode(provideNodeIdentifier(), getValue());
+        }
     }
 }