简体   繁体   English

如何在节点之间获取xml数据?

[英]How to get the xml data between the nodes?

I'm using .Net web service in my Android app.The service return the values between the Message tag like this: 我在我的Android应用程序中使用.Net Web服务。该服务返回Message标记之间的值,如下所示:

<Message> CustomerID=10 </Message>

Here, how can i take the data from this Message tag using Android? 在这里,我如何使用Android从此Message标签中获取数据?

I want to retrieve the information inside the xml received from the web service. 我想检索从Web服务收到的xml内的信息。

Thanks in advance. 提前致谢。

example for parsing xml : 解析xml示例:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db;
try {
    db = dbf.newDocumentBuilder();
    Document doc = null;
    doc = db.parse([InputStream]);
    NodeList nl = doc.getElementsByTagName("Message");
    if (nl != null) {
        for (int i = 0; i < nl.getLength(); i++) {
            Node item = nl.item(i);
            String name = item.getNodeName();
            String value = item.getTextContent();
        }
    }
}catch{}

You will get the value between the tags with 您将获得标签之间的值

item.getTextContent()

Using this example u will get your solution. 使用此示例,您将获得解决方案。 You doesn't worry about Tag that will be handle by Default Handler Only u want to declare Starting Tag SAX Sample only change tag ... 您不必担心默认处理程序将处理的标记只想声明开始标记SAX样本只更改标记...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM