0
        Visit_all_class parser = new Visit_all_class(); 
        String xml = parser.Call3(URL); // getting XML 
        Document doc = parser.getDomElement(xml); // getting DOM element 

        NodeList nl = doc.getElementsByTagName(KEY_VISIT); 

        // looping through all item nodes <item> 
        for (int i = 0; i < nl.getLength(); i++) { 
            // creating new HashMap 

            HashMap<String, String> map = new HashMap<String, String>(); 
            Log.v("map","map" +map);
            Element e = (Element) nl.item(i); 
            // adding each child node to HashMap key => value 
            map.put(KEY_ACCOUNTNUMBER, parser.getValue(e, KEY_ACCOUNTNUMBER)); 
            map.put(KEY_LOCATION, parser.getValue(e, KEY_LOCATION)); 
            map.put(KEY_NAME, parser.getValue(e, KEY_NAME)); 
            map.put(KEY_VISITID, parser.getValue(e, KEY_VISITID)); 
            map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION));
            map.put(KEY_LAST, parser.getValue(e, KEY_LAST));
            map.put(KEY_PLANNED, parser.getValue(e, KEY_PLANNED));
            map.put(KEY_COMPLETION, parser.getValue(e, KEY_COMPLETION));
            map.put(KEY_START, parser.getValue(e, KEY_START));
            map.put(KEY_STATUS, parser.getValue(e, KEY_STATUS));


            // adding HashList to ArrayList 
            menuItems1.add(map);

我已经解析了来自 web 服务的值并将其放在 menuItems 中。但是,我想从 web 服务中单独解析值并将其传递给为数据库创建的方法。

请建议如何从 web 服务中单独解析值的方法。

4

1 回答 1

0

这取决于如何org.w3c.dom.Document格式化,但您使用org.w3c.dom.Node接口中的方法。见这里

例如,如果您希望 XML 的格式如下:

...
<visit>
    <account_no>1234</account_no>
    <location>www.example.com/locaiton1</location>
    <name>Ammu</name>
</visit>
<visit>
    <account_no>4321</account_no>
    <location>www.example.com/locaiton2</location>
    <name>William</name>
</visit>
...

你会这样做:

Element e = (Element) nl.item(i); 
int accountNo = (int) e.getChildNodes().item(0).getTextContent();
String location = e.getChildNodes().item(1).getTextContent();
String name = e.getChildNodes().item(2).getTextContent();
于 2013-03-28T08:04:07.067 回答