Java????JDom?????????XML???????
???????????? ???????[ 2013/2/28 10:33:37 ] ????????
????Java????JDom??????????XML????????
??????????jdom-1.1.2.jar
????1?????????????XML???????????д???
Element rootList?? firstList?? secondItem?? thirdItem;
//?????????
rootList = new Element("root");
//???????????????????
rootList.setAttribute("project"?? pname);
//????Doc???
Document Doc = new Document(rootList);
//???????е?????
rootList = Doc.getRootElement();
for (int i = 0; i < judges.size(); i++)
{
//?????μ????
firstList = new Element("flayout");
firstList.setAttribute("percent"?? "percent");
//????????????
rootList.addContent(firstList);
}
XMLOutputter XMLOut = new XMLOutputter();
//??doc???????????????XML???
String xmlinfo = XMLOut.outputString(Doc);
//??????????
xmlinfo = xmlinfo.replace("<?xml version="1.0" encoding="UTF-8"?>"??
"");
//?????????????XML????
return xmlinfo;
????2??????????е?XML?????????д???
//????????μ??????
StringReader read = new StringReader(stadXML);
// ?????μ??????SAX ??????????? InputSource ???????????ζ?? XML ????
InputSource source = new InputSource(read);
// ????????μ?SAXBuilder
SAXBuilder sb = new SAXBuilder();
String projectName;
List<Judgestandard> standIndex = new ArrayList<Judgestandard>();
try {
// ???????????????Document
Document doc = sb.build(source);
// ???????
Element root = doc.getRootElement();
projectName = root.getAttributeValue("project");
// ?????????????????????
Element et = null;
List nodes = root.getChildren();
// ????????
for (int i = 0; i < nodes.size(); i++) {
et = (Element) nodes.get(i);// ??????ε???????
Judgestandard judge = new Judgestandard();
//????????????????
String fid = et.getAttributeValue("mainid");
//?????????????
List fsize = et.getChildren();
// ????????
for (int j = 0; j < fsize.size(); j++)
{
et = (Element) fsize.get(j);// ??????ε???????
et.getAttributeValue("stdid")
}
????Java????XML???
???????????
???????????XML?????
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<ip>localhost</ip>
<port>8080</port>
</root>
static DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
static DocumentBuilder builder = null;
builder = factory .newDocumentBuilder();
//????????????????
Document document = builder.parse(new File("src/ip.xml"));
Element rootElement = document.getDocumentElement();
NodeList list1 = rootElement.getElementsByTagName("ip");
NodeList list2 = rootElement.getElementsByTagName("port");
Element ip = (Element) list1.item(0);
Element port = (Element) list2.item(0);
String s =ip.getFirstChild().getNodeValue().toString()+":"+port.getFirstChild().getNodeValue().toString();
System.out.println(s);
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11