com.fordfrog.xml2csv.XmlStreamReaderConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xml-to-csv Show documentation
Show all versions of xml-to-csv Show documentation
Forked version of fordfrog xml2csv library that allows selection of xml elements via attributes
The newest version!
package com.fordfrog.xml2csv;
import javax.xml.stream.XMLStreamReader;
public class XmlStreamReaderConverter {
public String toLocalName(XMLStreamReader reader) {
StringBuilder name = new StringBuilder(reader.getLocalName());
if (reader.getAttributeCount() > 0)
for (int a = 0; a < reader.getAttributeCount(); a++)
name.append(toString(reader, a));
return name.toString();
}
private static String toString(XMLStreamReader reader, int attributeIndex) {
StringBuilder s = new StringBuilder();
s.append("[@");
s.append(reader.getAttributeLocalName(attributeIndex));
s.append("='");
s.append(reader.getAttributeValue(attributeIndex));
s.append("']");
return s.toString();
}
}