示例#1
0
 /**
  * Puts a new element into the DOM Document. The new element is added as a child to the current
  * element in the DOM document. Then it becomes the current element. The element must be closed
  * using closeElement.
  */
 public void openElement(String tagName) {
   XMLElement newElement = new XMLElement(); // new HashMap(), false, false);
   newElement.setName(tagName);
   current.addChild(newElement);
   stack.push(current);
   current = newElement;
 }
  public static void main(String args[]) throws Exception {
    if (args.length == 0) {
      System.err.println("Usage: java DumpXML file.xml");
      Runtime.getRuntime().exit(1);
    }

    IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
    IXMLReader reader = StdXMLReader.fileReader(args[0]);
    parser.setReader(reader);
    XMLElement xml = (XMLElement) parser.parse();

    xml.addChild(null);
    (new XMLWriter(System.out)).write(xml);
  }
  public XMLElement toXML() {
    XMLElement glElement = new XMLElement("GLDataLines");

    glElement.addChild(getXmlElement(transactionDate, "TransactionDate"));
    glElement.addChild(getXmlElement(accountID, "AccountID"));
    glElement.addChild(getXmlElement(accountName, "AccountName"));
    glElement.addChild(getXmlElement(transactionDescription, "TransactionDescription"));
    glElement.addChild(getXmlElement(name, "Name"));
    glElement.addChild(getXmlElement(transactionID, "TransactionID"));
    glElement.addChild(getXmlElement(sourceDocumentID, "SourceDocumentID"));
    glElement.addChild(getXmlElement(sourceType, "SourceType"));
    glElement.addChild(getXmlElement(debit, "Debit"));
    glElement.addChild(getXmlElement(credit, "Credit"));
    glElement.addChild(getXmlElement(balance, "Balance"));

    return glElement;
  }