XML格式如下:
<?xml version="1.0" encoding="GBK"?>
<elXmlIniPlus>
<Section SectionName="DCQRYITFA">
<elXmlProperty>
<Attribute key="PRJCOD" value="NJ012001" ></Attribute>
<Attribute key="BNKTYP" value="CMBHZ" ></Attribute>
<Attribute key="BNKCOD" value="CMB" ></Attribute>
<Attribute key="VERSON" value="A" />
<Attribute key="ITFNAM" value="招行杭州" />
<Attribute key="TRSFLG" value="Y" />
<Attribute key="BGNPAY" value="08:00:00" />
<Attribute key="ENDPAY" value="20:00:00" />
<Attribute key="INSFLG" value="N" />
<Attribute key="BGNTIM" value="04:00:00" />
<Attribute key="ENDTIM" value="23:00:00" />
</elXmlProperty>
</Section>
<Section SectionName="SYCOMRETZ">
<elXmlProperty>
<Attribute key="ERRCOD" value="0000000" />
<Attribute key="ERRMSG" value="" />
</elXmlProperty>
</Section>
<Section SectionName="DCQRYITFQ">
<elXmlProperty>
<Attribute key="PRJCOD" value="NJ012004" ></Attribute>
<Attribute key="BNKTYP" value="CMBHZW" ></Attribute>
<Attribute key="BNKCOD" value="CMB" ></Attribute>
<Attribute key="VERSON" value="A" />
<Attribute key="ITFNAM" value="招行杭州WW" />
<Attribute key="TRSFLG" value="Y" />
<Attribute key="BGNPAY" value="08:00:00" />
<Attribute key="ENDPAY" value="20:00:00" />
<Attribute key="INSFLG" value="N" />
<Attribute key="BGNTIM" value="04:00:00" />
<Attribute key="ENDTIM" value="23:00:00" />
</elXmlProperty>
</Section>
</elXmlIniPlus>
处理类:
package com.cmb.fbcbcserver.api.internal.parser.xml;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class IniPlus {
/**
* <Description>
*
* @since Aug 2, 2012
* @param args <Description>
* @throws Exception
*
*/
public static void main(String[] args) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder
.parse("E:\\2012Project\\CbcSdk1.0\\src\\com\\cmb\\fbcbcserver\\api\\internal\\parser\\xml\\aa.xml");
Element root = doc.getDocumentElement();
System.out.println("根节点名字:" + root.getTagName());
NodeList secNodes = root.getElementsByTagName("Section");
for (int i = 0; i < secNodes.getLength(); i++) {
Element secElement = (Element) secNodes.item(i);
System.out.println("section name:"+secElement.getAttribute("SectionName"));
NodeList proNodes = secElement.getElementsByTagName("elXmlProperty");
for (int j = 0; j < proNodes.getLength(); j++) {
Element proElement = (Element) proNodes.item(j);
NodeList attriNodes = proElement.getChildNodes();
for (int z = 0; z < attriNodes.getLength(); z++) {
if (attriNodes.item(z).getNodeType() == Node.ELEMENT_NODE) {
Element attriElement = (Element)attriNodes.item(z);
System.out.println("key:"+attriElement.getAttribute("key")+" value:" + attriElement.getAttribute("value"));
}
}
}
System.out.println("--------");
}
}
}
请注意:dom会将所有xml加载到内存中,然后解析。