dom4j 问题 请各位大神指导一下!
public class XMLTest {
/**
* @param args
* @throws DocumentException
*/
public static void main(String[] args) throws DocumentException {
String str = "<?xml version='1.0' encoding='GB2312' ?>" +
"<GameRegion>" +
"<GameRegionInfo CategoryCode='AASZQFYQKV' CategoryName='云游卡(墨香/傲视天地/凡人修真/天地英雄/斗法修仙/南帝北丐)'>" +
"<GameRegionItem RegionID='5250' RegionName='云起点' RegionValue='0' List_Order='0' />" +
"<GameRegionItem RegionID='5414' RegionName='天地英雄' RegionValue='120' List_Order='0' />" +
"<GameRegionItem RegionID='5711' RegionName='梦幻修仙' RegionValue='122' List_Order='0' />" +
"<GameRegionItem RegionID='5252' RegionName='凡人修真' RegionValue='109' List_Order='0' />" +
"<GameRegionItem RegionID='5712' RegionName='乱世群雄' RegionValue='123' List_Order='0' />" +
"<GameRegionItem RegionID='5549' RegionName='斗法修仙' RegionValue='129' List_Order='0' />" +
"<GameRegionItem RegionID='5550' RegionName='南帝北丐' RegionValue='136' List_Order='0' />" +
"<GameRegionItem RegionID='5256' RegionName='傲视天地' RegionValue='99' List_Order='0' />" +
"<GameRegionItem RegionID='5597' RegionName='墨香Online' RegionValue='49' List_Order='0' />" +
"</GameRegionInfo>" +
"</GameRegion>";
// TODO Auto-generated method stub
Document document = DocumentHelper.parseText(str);
Element users=document.getRootElement();
for(Iterator iter= users.elementIterator(); iter.hasNext(); ){
Element element = (Element)iter.next();
Attribute CategoryCode = element.attribute("CategoryCode");
Attribute CategoryName = element.attribute("CategoryName");
Attribute RegionID = element.attribute("RegionID");
Attribute RegionName = element.attribute("RegionName");
Attribute RegionValue = element.attribute("RegionValue");
System.out.println(CategoryCode.getText());
System.out.println(CategoryName.getText());
System.out.println(RegionID.getText());
System.out.println(RegionName.getText());
System.out.println(RegionValue.getText());
}
}
}
请问一下,如何获取:GameRegionItem这个子节点里面的的属性值呢?,如果GameRegionItem里面还有子节点呢?------解决方案--------------------
不知道能不能帮到你,就当一个思路吧。
<body>
<table>
<tr id="tr1">
<td id="td1" name="td1">
<p id="p1">aaaaaa</p>
dddd
<a href="#" style="color:blue" id="a1">1111111111111</a>
</td>
</tr>
<tr>
<td id="td2">
<a href="#" style="color:red" id="a2">22222222222</a>
</td>
</tr>
<tr>
<td>
<input type="button" value="添加节点" onclick="createChildNode('td1')" />
<input type="button" value="删除节点" onclick="removeChildNode('td1')" />
<input type="button" value="innerHTML" onclick="a('td1')" />
</td>
</tr>
</table>
</body>
</html>
<script language="JavaScript" type="text/javascript">
function removeChildNode(id)
{
//alert("aaaaaaaaaa");
var test = document.getElementById(id);
var children = test.childNodes;
//alert(children.length);