private static void writeElement(XMLStreamWriter xtw, Element element) throws XMLStreamException { xtw.writeStartElement(element.getName()); for (String attributeName : element.getAttributeNames()) { xtw.writeAttribute(attributeName, element.getAttributeValue(attributeName)); } if (element.hasText()) { xtw.writeCharacters(element.getText()); } else { for (Element child : element.getChildren()) { writeElement(xtw, child); } } xtw.writeEndElement(); }
public void exportAsXML(XMLStreamWriter xmlWriter) throws IOException, XMLStreamException { if (xmlWriter == null) { String message = Logging.getMessage("Export.UnsupportedOutputObject"); Logging.logger().warning(message); throw new IllegalArgumentException(message); } xmlWriter.writeStartElement("Record"); xmlWriter.writeAttribute("id", Integer.toString(this.getRecordNumber())); xmlWriter.writeAttribute( "shape", this.getShapeType().substring(this.getShapeType().lastIndexOf("Shape") + 5)); xmlWriter.writeAttribute("parts", Integer.toString(this.getNumberOfParts())); xmlWriter.writeAttribute("points", Integer.toString(this.getNumberOfPoints())); xmlWriter.writeCharacters("\n"); for (Map.Entry<String, Object> a : this.getAttributes().getEntries()) { xmlWriter.writeStartElement("Attribute"); xmlWriter.writeAttribute("name", a.getKey() != null ? a.getKey().toString() : ""); xmlWriter.writeAttribute("value", a.getValue() != null ? a.getValue().toString() : ""); xmlWriter.writeEndElement(); // Attribute xmlWriter.writeCharacters("\n"); } if (this.getNumberOfParts() > 0) { VecBuffer vb = this.getPointBuffer(0); for (LatLon ll : vb.getLocations()) { xmlWriter.writeStartElement("Point"); xmlWriter.writeAttribute("x", Double.toString(ll.getLatitude().degrees)); xmlWriter.writeAttribute("y", Double.toString(ll.getLongitude().degrees)); xmlWriter.writeEndElement(); // Point xmlWriter.writeCharacters("\n"); } } // TODO: export record-type specific fields xmlWriter.writeEndElement(); // Record }