Dom4j解析xml字符

package componet;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import java.util.Iterator;
import java.util.Properties;

import javax.jws.Oneway;
import javax.jws.WebMethod;
import javax.jws.WebService;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

@WebService(name = "MyWebService1", serviceName = "MyWebService1", portName = "MyWebService1SoapHttpPort")
public class Canvas {
private Connection conn = null;
private Statement stmt = null;
private ResultSet rs = null;
public Canvas() {
}
@WebMethod
@Oneway
public void SetLayout(String msg){
try {

Document doc = DocumentHelper.parseText(msg);
Element root1 = doc.getRootElement();
Iterator it = root1.elements().iterator();
while(it.hasNext()){
Element info = (Element)it.next();
System.out.print(info.attribute("type").getValue());
System.out.print(info.attribute("ID").getValue());
System.out.print(info.attribute("title").getValue());
System.out.print(info.attribute("x").getValue());
System.out.print(info.attribute("y").getValue());
System.out.print(info.attribute("width").getValue());
System.out.print(info.attribute("height").getValue());
System.out.print(info.attribute("csub").getValue());
System.out.println();
}

} catch (DocumentException e) {
e.printStackTrace();

}

}

public static void main(String[] args) {
Canvas obj = new Canvas();
String str = "<foc>
<item type = \"MultiButtonPanel \" ID = \"window1 \" title = \"window1 \" x = \"531 \" y = \"256 \" width = \"230 \" height = \"86 \" csub = \"0 \"/>
<item type = \"MultiButtonPanel \" ID = \"window2 \" title = \"window2 \" x = \"231 \" y = \"226 \" width = \"260 \" height = \"126 \" csub = \"1 \"/>
</foc>";
obj.SetLayout(str);
}
}
运行结果:
MultiButtonPanel window1 window1 531 256 230 86 0
MultiButtonPanel window2 window2 231 226 260 126 1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值