JAVA Xmlconfiguration solves stringxml and multi-node __java

Source: Internet
Author: User
Import org.apache.commons.configuration.ConfigurationException;
Import org.apache.commons.configuration.HierarchicalConfiguration;
Import Org.apache.commons.configuration.HierarchicalConfiguration.Node;

Import org.apache.commons.configuration.XMLConfiguration; public class Parsexmdemo {private static String Parsemutlilines (Hierarchicalconfiguration lineconfig) {String value
		="";
		Node root = Lineconfig.getroot ();

		List children = Root.getchildren ();
		int count = 0;
			for (int i = 0; i < children.size (); i++) {Node child = (node) children.get (i);
			if ("point". Equals (Child.getname ()) {count++;
			(int i = 0; i < count; i++) {Value + = lineconfig.getstring ("point (+ i +") [@x]);
			Value + = ",";
			Value + + lineconfig.getstring ("point" ("+ i +") [@y]);
		Value + = ":";
	return value; public static void Main (stirng[] args) {String xml = "<csMsgsReq>" + "<csmsgreq xsi:type=\" csty Penotify\ ">" + "<authority xsi:type=\ "cstypeauthoritycommon\"/> "+" <nbase xsi:type=\ "cstypealarmgeneral\" > "+" <alarmT Ime>2014-10-09t17:16:54.687</alarmtime> "+" <trackline xsi:type=\ "cstypetracklinetype\" lineLth=\ "24\" > "+" <point xsi:type=\ "cstypepoint\" x=\ "0\" y=\ "0\"/> "+" <point xsi:type=\ "cstypepoint\" X= \ "1386\" y=\ "472\"/> "+" </TrackLine> "+" </nbase> "+" </csMsgReq> "+" &LT;/CSM
		Sgsreq> ";
		InputStream in = new Bytearrayinputstream (Xml.getbytes ());
		xmlconfiguration config = new xmlconfiguration ();
			try {config.load (in); 
			String alarmtime = config.getstring ("CsMsgReq.nbase.alarmTime");
			Hierarchicalconfiguration lineconfig = (hierarchicalconfiguration) config.subset ("CsMsgReq.nbase.TrackLine");
		String trackline = Parsemutlilines (lineconfig);
		catch (ConfigurationException e) {e.printstacktrace (); }
	}
	

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.