import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
class ReadXMLFromServer {
public static void main
(String [] args
){ parseFile();
}
public static void parseFile() {
//get the factory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
String url
= "http://t...content-available-to-author-only...b.net/Trip/rs/TripService/v1/Trip/c1d52b4d-7342-40f2-90fe-64ee173662b2";
//Using factory get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();
//parse using builder to get DOM representation of the XML file
//Document dom = db.parse("employees.xml");
//get the root element
Element docEle
= dom.
getDocumentElement(); //get a nodelist of elements
NodeList nl = docEle.getElementsByTagName("ReadTripResponse");
if (nl != null && nl.getLength() > 0) {
for (int i = 0; i < nl.getLength(); i++) {
//get the employee element
String firstname
= getTextValue
(el,
"TripID"); //String lastname = getTextValue(el, "lastname");
// String nickname = getTextValue(el, "nickname");
// int salary = getIntValue(el, "salary");
System.
out.
println(firstname
); // System.out.println(lastname);
// System.out.println(nickname);
// System.out.println(salary);
}
}
e.printStackTrace();
}
}
NodeList nl = ele.getElementsByTagName(tagName);
if (nl != null && nl.getLength() > 0) {
textVal = el.getFirstChild().getNodeValue();
}
return textVal;
}
return Integer.
parseInt(getTextValue
(ele, tagName
)); }
}