Here is my code using XmlPullParser . strings.xml just included "<foo>Hello world</foo>" when I read the log. Some String characters are read including "Hello world" is it the problem of input encoding? btw, how to solve this probleM?
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); XmlPullParser xpp = factory.newPullParser(); xpp.setInput(getResources().openRawResource(R.xml.strings),null); int eventType = xpp.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if(eventType == XmlPullParser.START_DOCUMENT) { Log.d("testing","Start document"); } else if(eventType == XmlPullParser.END_DOCUMENT) { Log.d("testing","End document"); } else if(eventType == XmlPullParser.START_TAG) { Log.d("testing","Start tag "+xpp.getName()); } else if(eventType == XmlPullParser.END_TAG) { Log.d("testing","End tag "+xpp.getName()); } else if(eventType == XmlPullParser.TEXT) { Log.d("testing","Text "+xpp.getText()); } eventType = xpp.next(); } On Feb 19, 10:50 pm, Mark Murphy <mmur...@commonsware.com> wrote: > CMF wrote: > > I have my code here > > > Document dom; > > DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); > > try > > { > > DocumentBuilder db = dbf.newDocumentBuilder(); > > dom = > > db.parse("strings.xml"); // > > here I don't know the path of strings.xml which is in the res/values. > > }catch(ParserConfigurationException pce) { > > pce.printStackTrace(); > > }catch(SAXException se) { > > se.printStackTrace(); > > }catch(IOException ioe) { > > ioe.printStackTrace(); > > } > > > ...// which I expect I can get the content needed ...but the keypoint > > is , i dont know how to read the res/values/strings.xml as the input > > stream. > > You cannot read res/values/strings.xml as XML. If you want XML > resources, put them in res/xml and use the Resources object to get an > XmlPullParser. > > -- > Mark Murphy (a Commons > Guy)http://commonsware.com|http://twitter.com/commonsguy > > Android Training in US: 14-18 June 2010:http://bignerdranch.com -- 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