Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.webservicemart.ws.*;
- import java.io.*;
- import javax.xml.parsers.*;
- import org.w3c.dom.*;
- import org.xml.sax.*;
- public class ZipWSTest {
- public static void main(String[] args) {
- USZip usZip = new USZip();
- USZipSoap usZipSoap = usZip.getUSZipSoap();
- String response = usZipSoap.validateZip("08863");
- response = "<?xml version='1.0'?><root>"+response+"</root>";
- try {
- Document doc = XMLUtility.stringToDom(response);
- NodeList nl = doc.getElementsByTagName("item");
- Node n = nl.item(0);
- NamedNodeMap nnmap = n.getAttributes();
- String state = nnmap.getNamedItem("state").getNodeValue();
- String lat = nnmap.getNamedItem("latitude").getNodeValue();
- String lng = nnmap.getNamedItem("longitude").getNodeValue();
- System.out.println("State:"+state);
- System.out.println("Latitude:"+lat);
- System.out.println("Longitude:"+lng);
- }catch(Exception e){
- System.out.println("Error:"+e);
- }
- System.out.println("XML:" + response);
- }
- public static class XMLUtility {
- public static Document stringToDom(String xmlSource)
- throws SAXException, ParserConfigurationException, IOException {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- return builder.parse(new InputSource(new StringReader(xmlSource)));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement