package xin.glue.ui.G.G07; import java.io.FileOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStream; import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; import com.sun.org.apache.xerces.internal.dom.DocumentImpl; import com.sun.org.apache.xml.internal.serialize.OutputFormat; import com.sun.org.apache.xml.internal.serialize.XMLSerializer; import java.util.Hashtable; import java.util.ArrayList; public class DomXmlParser{ DocumentBuilderFactory domfac = null; DocumentBuilder dombuilder = null; private ArrayList items = new ArrayList(); String revStr = null; String xpath = null; String docId = null; private int strLenTagFrom = 0; private int strLenTagto = 0; public DomXmlParser( String xpath){ this.xpath = "E:\\XML_PARSE\\" + xpath + "-msg.xml"; } public void setRevStr(String revStr){ this.revStr = revStr; } public ArrayList getItems(){ return items; } public void runDomXmlParser(){ try{ domfac=DocumentBuilderFactory.newInstance(); dombuilder=domfac.newDocumentBuilder(); InputStream is = new FileInputStream(xpath); Document doc=dombuilder.parse(is); Element root=doc.getDocumentElement(); NodeList msgs=root.getChildNodes(); if(msgs != null){ for(int i = 0 ; i< msgs.getLength() ; i++){ Node msg = msgs.item(i); if(msg.getNodeType() == Node.ELEMENT_NODE){ docId = msg.getAttributes().getNamedItem("id").getNodeValue(); NodeList attributes = msg.getChildNodes(); if(attributes != null){ for(int j = 0 ; j < attributes.getLength() ; j++){ Node attribute = attributes.item(j); if(attribute.getNodeType() == Node.ELEMENT_NODE){ Hashtable ht = new Hashtable(); String seq = attribute.getAttributes().getNamedItem("seq").getNodeValue(); String id = attribute.getAttributes().getNamedItem("id").getNodeValue(); String name = attribute.getAttributes().getNamedItem("name").getNodeValue(); String datatype = attribute.getAttributes().getNamedItem("datatype").getNodeValue(); String length = attribute.getAttributes().getNamedItem("length").getNodeValue(); ht.put("seq",seq); ht.put("id",id); ht.put("name",name); ht.put("datatype",datatype); ht.put("length",length); items.add(ht); } } } } } } } catch (ParserConfigurationException e){ e.printStackTrace(); } catch (FileNotFoundException e){ e.printStackTrace(); } catch (SAXException e){ e.printStackTrace(); } catch (IOException e){ e.printStackTrace(); } } private void displayItes(){ for(int i=0;i