में xml से पोते प्राप्त करने वाले मुझे कुछ txt फ़ाइल में एक XML फ़ाइल की सामग्री को मुद्रित करने की आवश्यकता है। यहाँ xml का प्रकार का एक नमूना मैं बाहर प्रिंट करना चाहते है:जावा
<log>
<logentry revision="234">
<author>SOMEGUY</author>
<date>SOME DATE</date>
<paths>
<path>asdf/asdf/adsf/asdf.zip</path>
</path>
<msg>blahblahblah</msg>
</logentry>
</log>
मैं सभी जानकारी मैं की जरूरत है, पथ टैग के अलावा प्राप्त कर सकते हैं ... यह मैं क्या किया है है:
FileWriter fstream = new FileWriter("c:\\work\\output.txt");
BufferedWriter out = new BufferedWriter(fstream);
Document document = (Document) builder.build(xmlFile);
Element rootNode = document.getRootElement();
List list = rootNode.getChildren("logentry");
for (int i=0; i< list.size(); i++) {
Element node = (Element) list.get(i);
out.write("Revision: \n" + node.getAttributeValue("revision") + "\n\n");
out.write("Author: \n" + node.getChildText("author") + "\n\n");
out.write("Date: \n" + node.getChildText("date") + "\n\n");
out.write("Message: \n" + node.getChildText("msg"));
out.write("\n-------------------------------------------------"
+"---------------------------------------------------\n\n");
}
out.close();
तो, शैतान को मुझे उस टैग से जानकारी कैसे प्राप्त होती है?
पीएस गुमनामी में इस downvote के लिए स्वतंत्र महसूस अगर यह के रूप में आप भी एक जवाब :) की ओर मुझे निर्देशित
धन्यवाद
एक बेवकूफ सवाल है ... इतने लंबे समय
आप JDom से बंधा रहे हैं? क्या आपने सोचा है कि क्या XPath आपकी समस्या को हल करने के लिए उपयुक्त होगा? –