Android™
Android™
XML GetChildWithAttr
See more XML Examples
Demonstrates how to get the content of a particular node with a particular attribute. For example, returns "Face up in the Rain" for the Name="Album" node.<Response Status="OK"> <Item Name="ZoneID">0</Item> <Item Name="State">2</Item> <Item Name="FileKey">305718</Item> <Item Name="Artist">Michael Tomlinson</Item> <Item Name="Album">Face Up in the Rain</Item> <Item Name="Name">The Way We're Going</Item> <Item Name="Status">Playing</Item> </Response>
Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean success = false;
CkXml xml = new CkXml();
success = xml.LoadXmlFile("qa_data/resp.xml");
if (success != true) {
Log.i(TAG, xml.lastErrorText());
return;
}
CkXml xItem = xml.GetChildWithAttr("Item","Name","Album");
if (xml.get_LastMethodSuccess() == false) {
Log.i(TAG, "not found.");
return;
}
Log.i(TAG, xItem.content());
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}