feat(serialize-xml): Add NativeXmlReader.copyTo
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2024-04-20 19:49:07 +02:00
parent 400a2cf654
commit d99c129a06
Signed by: Johannes
GPG Key ID: E76429612C2929F4
1 changed files with 29 additions and 0 deletions

View File

@ -822,4 +822,33 @@ public class NativeXmlReader implements Closeable {
stackSize = 1;
in.close();
}
/**
* Copies the current element to the writer.
*
* @param writer the writer to copy to
* @throws IOException if an error occurs
*/
public void copyTo(NativeXmlWriter writer) throws IOException {
switch (peek()) {
case BEGIN_TAG -> {
beginTag();
writer.beginTag(pathNames[stackSize - 1]);
while (hasNext()) {
copyTo(writer);
}
endTag();
writer.endTag();
}
case END_TAG -> throw new IllegalStateException("Cannot copy standalone END_TAG");
case TEXT -> writer.text(nextText());
case CDATA -> writer.cdata(nextCData());
case ATTRIBUTE_NAME -> {
String name = nextAttributeName();
writer.attribute(name, nextAttributeValue());
}
case ATTRIBUTE_VALUE -> writer.attributeValue(nextAttributeValue());
case EOF -> throw new IllegalStateException("Cannot copy END_DOCUMENT");
}
}
}