示例#1
0
 private static void checkCRC(Element element) throws CRCMismatchException {
   Element CRCElement = element.getChild(CRC_ELEMENT);
   if (CRCElement != null) {
     String crc = CRCElement.getText();
     // the length in bytes is the number of characters divided by 2
     int crcLength = crc.length() / 2;
     if (!crc.equals(element.getHash(crcLength, CRC_ELEMENT))) {
       throw new CRCMismatchException();
     }
   }
 }
示例#2
0
 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();
 }