Yes, that's a completely different question than getting data from res/ values/strings.xml -- even though they look like the same thing!
It's also an easy question you would have answered yourself, were you not expecting there to be an event! A reasonable idea, but incorrect, and that's what's confusing you. There is not a separate event for attributes. You get attributes when you process the START_TAG event. See the XmlPullParser.getAttributeCount() method, and the XmlPullParser.getAttributeXXX(int), family of methods. On Feb 19, 9:43 am, CMF <[email protected]> wrote: > Um, lets make my question more explicitly here. > I have a xml file "myfile.xml" > which the content is: > <root> > <node name="a">contenta</node> > <node name="b">contentb</node> > ... > <node name="aa">contentaa</node> > ... > </root> > > the myfile.xml is placed at res/xml/ > I would like to get all the node( but don't know how many) attribute > "name", as well as the corresponding content. > > On Feb 20, 1:07 am, Frank Weiss <[email protected]> wrote: > > > > > It's not clear what you are trying to accomplish, but it looks like you > > don't understand how the res/values/strings.xml and R object work. The > > Android builder takes the data defined in the xml file and generates a Java > > source file that contains that data. The Android application can then get > > that data directly from the R object at run time. > > > If you are trying to put some XML in strings.xml, do as Mark said, but > > obtain it as a String from the R object first: > > > String myXml = R.xml.string; > > > Then have your parser parse that string, myXml. > > > On Fri, Feb 19, 2010 at 8:01 AM, CMF <[email protected]> wrote: > > > 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 <[email protected]> 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 [email protected] > > > To unsubscribe from this group, send email to > > > [email protected]<android-developers%2Bunsubs > > > [email protected]> > > > For more options, visit this group at > > >http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

