मैं सभी "<Type>
" तत्वों को ले कर एक URL से एक XML फ़ाइल को पार्स करने का प्रयास कर रहा हूं जहां पैरामीटर टाइप_आईडी = "4218" है ??विशिष्ट विशेषता मान के साथ विशिष्ट XML तत्व कैसे प्राप्त करें?
XML दस्तावेज़:
<BSQCUBS Version="0.04" Date="Fri Dec 9 11:43:29 GMT 2011" MachineDate="Fri, 09 Dec 2011 11:43:29 +0000">
<Class class_id="385">
<Title>Football Matches</Title>
<Type type_id="4264" type_minbet="0.1" type_maxbet="2000.0">
...
</Type>
<Type type_id="5873" type_minbet="0" type_maxbet="0">
...
</Type>
<Type type_id="4725" type_minbet="0.1" type_maxbet="2000.0">
...
</Type>
<Type type_id="4218" type_minbet="0.1" type_maxbet="2000.0">
...
</Type>
<Type type_id="4221" type_minbet="0.1" type_maxbet="2000.0">
...
</Type>
<Type type_id="4218" type_minbet="0.1" type_maxbet="2000.0">
...
</Type>
<Type type_id="4299" type_minbet="0.1" type_maxbet="2000.0">
...
</Type>
</Class>
</BSQCUBS>
यहाँ मेरी जावा कोड है:
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new URL("http://cubs.bluesq.com/cubs/cubs.php?action=getpage&thepage=385.xml").openStream());
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("Type");
System.out.println("ukupno:"+nodeList.getLength());
if (nodeList != null && nodeList.getLength() > 0) {
for (int j = 0; j < nodeList.getLength(); j++) {
Element el = (org.w3c.dom.Element) nodeList.item(j);
type_id = Integer.parseInt(el.getAttribute("type_id"));
System.out.println("type id:"+type_id);
}
}
इस कोड को मुझे सभी तत्वों को देता है, मुझे लगता है कि, मैं सभी तत्वों को चाहते हैं नहीं करना चाहती है, जहां विशेषता type_id = "4218"!
मैं कैसे की तरह ऑपरेटर के साथ type_id में मूल्य के लिए खोज –