Java Reference
In-Depth Information
URLConnection http = url.openConnection();
http.setDoOutput(true);
OutputStream os = http.getOutputStream();
os.write(request.getBytes());
InputStream is = http.getInputStream();
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
Document d = factory.newDocumentBuilder().parse(is);
Element e = d.getDocumentElement();
Node stateNode = getXMLNode(e,"state");
String id = getXMLAttribute(stateNode,"id");
System.out.println( "State Name:"
+ getXMLText(e,"state.name") );
System.out.println( "Code:" + getXMLText(e,"state.code") );
System.out.println( "Capital:"
+ getXMLText(e,"state.capital") );
System.out.println( "URL:" + getXMLText(e,"state.url") );
System.out.println( "ID:" + id);
}
/**
* Typical Java main method, create an object, and then
* start the object passing arguments. If insufficient
* arguments are provided, then display startup
* instructions.
*
* @param args Program arguments.
*/
public static void main(String args[])
{
try
{
if (args.length != 1)
{
System.out.println(
"Usage:\njava AjaxXML [state code, i.e. MO]");
} else
{
AjaxXML d = new AjaxXML();
d.process(args[0]);
}
} catch (Exception e)
{
Search WWH ::




Custom Search