您的位置:首页 > 其它

W3CDom操作XML文档实用工具类

2016-03-10 16:43 549 查看
public class XmlUtils {

/**
*	表达式的格式如:project.profiles.profile,返回最后一个定位到的单个标签
*
*/
public static Element getElement(Element ele, String exp) {
String[] tags = exp.split("\\.");
for (String tag : tags) {
NodeList nodeList = ele.getElementsByTagName(tag);
if (nodeList.getLength() > 0) {
ele = (Element) nodeList.item(0);
} else {
return null;
}
}
return ele;
}

/**
*	表达式的格式如:project.profiles.profile,返回最后一个定位到的标签列表
*
*/
public static NodeList getElements(Element ele, String exp) {
String[] tags = exp.split("\\.");
NodeList nodeList = null;
for (String tag : tags) {
nodeList = ele.getElementsByTagName(tag);
if (nodeList.getLength() == 0) {
return null;
}
ele = (Element) nodeList.item(0);
}
return nodeList;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  xml tags 标签