Do you have more information on this problem?  I tried to reproduce it and 
could not do so.  The following works as I would expect, parsing correct 
XML and generating error messages on malformed XML on emulators running ICS 
(4.0.4) and HC (3.2).

G. Blake Meike
Marakana

The second edition of Programming Android is now on-line:
http://shop.oreilly.com/product/0636920023005.do


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.xml);

((Button) findViewById(R.id.button)).setOnClickListener(
new View.OnClickListener() {
@Override public void onClick(View v) {
EditText txt = (EditText) findViewById(R.id.xml);
txt.setText(parseXml(txt.getText().toString()));
} });
}

String parseXml(String xml) {
String ret;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xml));
Document document = builder.parse(is);
Element root = document.getDocumentElement();
root.normalize();

NodeList items = root.getElementsByTagName("tag");
StringBuilder str = new StringBuilder();
for (int i = 0; i < items.getLength(); i++) {
Node node = items.item(i);
str.append(node.getNodeName()).append("|");
}

ret = str.toString();
}
catch (Exception e) {
ret = e.toString();
}

return ret;
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to