- /**
- * Write an InstanceIdentifier into the output stream. Calling corresponding {@link XMLStreamWriter#writeStartElement(String)}
- * and {@link XMLStreamWriter#writeEndElement()} is the responsibility of the caller.
- *
- * @param writer XML Stream writer
- * @param id InstanceIdentifier
- * @throws XMLStreamException
- */
- public static void write(final @Nonnull XMLStreamWriter writer, final @Nonnull YangInstanceIdentifier id) throws XMLStreamException {
- Preconditions.checkNotNull(writer, "Writer may not be null");
- Preconditions.checkNotNull(id, "Variable should contain instance of instance identifier and can't be null");
-
- final RandomPrefix prefixes = new RandomPrefix();
- final String str = XmlUtils.encodeIdentifier(prefixes, id);
-
- for (Entry<URI, String> e: prefixes.getPrefixes()) {
- writer.writeNamespace(e.getValue(), e.getKey().toString());
- }
- writer.writeCharacters(str);
- }
-
- /**
- * Write a full XML document corresponding to a CompositeNode into an XML stream writer.
- *
- * @param writer XML Stream writer
- * @param data data node
- * @param schema corresponding schema node, may be null
- * @throws XMLStreamException if an encoding problem occurs
- */
- public void writeDocument(final @Nonnull XMLStreamWriter writer, final @Nonnull CompositeNode data, final @Nullable SchemaNode schema) throws XMLStreamException {
- // final Boolean repairing = (Boolean) writer.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES);
- // Preconditions.checkArgument(repairing == true, "XML Stream Writer has to be repairing namespaces");
-
- writer.writeStartDocument();
- writeElement(writer, data, schema);
- writer.writeEndDocument();
- writer.flush();
- }
-
- /**
- * Short-hand for {@link #writeDataDocument(XMLStreamWriter, CompositeNode, SchemaNode, XmlCodecProvider)} with
- * null SchemaNode.
- *
- * @param writer XML Stream writer
- * @param data data node
- * @param schema corresponding schema node, may be null
- * @throws XMLStreamException if an encoding problem occurs
- */
- public void writeDocument(final XMLStreamWriter writer, final CompositeNode data) throws XMLStreamException {
- writeDocument(writer, data, null);
+ @VisibleForTesting
+ static void writeAttribute(final XMLStreamWriter writer, final Entry<QName, String> attribute, final RandomPrefix randomPrefix)
+ throws XMLStreamException {
+ final QName key = attribute.getKey();
+ final String prefix = randomPrefix.encodePrefix(key.getNamespace());
+ writer.writeAttribute("xmlns:" + prefix, key.getNamespace().toString());
+ writer.writeAttribute(prefix, key.getNamespace().toString(), key.getLocalName(), attribute.getValue());