????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);