0

I want to get the description, vendor and price from the following web service. [link] http://sagt.vizushop.com/DefaultSimple.aspx?command=item_price&id=11

response as follows

<item_details>
<description>
Jakl (Kumbuk) Center Table Timber : Mahogany/Rubber
</description>
<price>12600</price>
<vendor>BLUE</vendor>
</item_details>

I tried with the following example, but it doesn't work-gives null values for the variables.

                String vendor="";
                String price="";
                String description="";
                try {

                    URL url = new URL("http://sagt.vizushop.com/DefaultSimple.aspx?command=item_price&id=11");
                    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                    DocumentBuilder db = dbf.newDocumentBuilder();
                    Document doc = db.parse(new InputSource(url.openStream()));
                    doc.getDocumentElement().normalize();

                    NodeList nodeList = doc.getElementsByTagName("description");
                    //description=nodeList.item(0).getNodeValue();
                    Node node = nodeList.item(0);

                    description = node.getNodeValue();


                    Log.v(TAG, description);
               }

1 Answer 1

1

If any one need this is the answer.

                        URL url = new URL("http://sagt.vizushop.com/DefaultSimple.aspx?command=item_price&id=11");
                    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                    DocumentBuilder db = dbf.newDocumentBuilder();
                    Document doc = db.parse(new InputSource(url.openStream()));
                    doc.getDocumentElement().normalize();

                    NodeList nodeList = doc.getElementsByTagName("item_details");

                    Node node=nodeList.item(0);

                    Element fstElmnt = (Element) node;
                    NodeList idList = fstElmnt.getElementsByTagName("price");
                    Element idElement = (Element) idList.item(0);
                    idList = idElement.getChildNodes();
                    price=((Node) idList.item(0)).getNodeValue();

                    Element secondElmnt = (Element) node;
                    NodeList vdList = secondElmnt.getElementsByTagName("vendor");
                    Element vdElmnt = (Element) vdList.item(0);
                    vdList = vdElmnt.getChildNodes();
                    vendor=((Node) vdList.item(0)).getNodeValue();


                    Element lastElemnt = (Element) node;
                    NodeList desList = lastElemnt.getElementsByTagName("description ");
                    Element desElmnt = (Element) desList.item(0);
                    desList = desElmnt.getChildNodes();
                    description=((Node) desList.item(0)).getNodeValue();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.