Method for reading XML node values ​​in a simple environment

xiaoxiao2021-03-06  66

Import

Javax.xml.parsers.

*

;

Import

Org.w3c.dom.

*

;

public

Class

XMLTest

...

{Public static void main (String [] args) ... {Document doc = null; try ... {DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance (); DocumentBuilder builder = factory.newDocumentBuilder (); doc = builder.parse ( " Chicang.xml "); doc.normalize ();} catch (exception e) ... {system.out.println (e);} //system.out.println (DocuMETDocuMENTELEMENT () GetNodename ()) /// Root node is N0, the first layer is N1, the second layer is N2, and so on / ** // * nodelist n1 = doc.getdocumentelement (). GetChildNodes (); nodelist [] n2 = nodeplus.getsublist (N1); nodelist [] n3 = nodeplus.getsublist (N2 [0]); * ///system.out.println (N2 [0] .getLength ()); //nodeplus.print(N3); // Nodelist n2 = getnodes.getchildlist (nodelist nv = doc.getListSbyTagname ("value"); // nodelist nk = doc.getlementsBytagname ("key"); string [] v = new string [nv.getlength ()] ; // string [] k = new string [nk.getLength ()]; for (int i = 0; i

---------- End of Accountinfo -------- "); for (int i = 3; i <6; i ) ... {Money [i-3] = v [ I]; system.out.println (Money [I-3]);} system.out.println ("-------- End of Money --------"); } / ** /

/ * Class NodePlus {// Nodelist for each element of NodeList, contains invalid nodes, stored as nodelist [] passublist (nodelist nl) {nodelist [] nlist = new nodelist [getnum (nl) ]; Int J = 0; for (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-87125.html

New Post(0)