Dom パーサーを使用して次の xml ファイルを解析しようとしていますが、最初の 3 つのタグ (日付、朝食、昼食) を取得しています。日付、朝食、昼食のすべてのタグを取得する方法。
-<Content>
<Date>2/4/2013</Date>
<Breakfast>WG Biscuit, Grits, sausage patty, fruit, juice, milk</Breakfast>
<Lunch>Chicken tenders with sauce, WG affle stick and syrup, carrots-MC, romaine garden salad, fruit, juice, milk</Lunch>
<Date>2/5/2013</Date>
<Breakfast>grilleed cheese sandich, grits, fruit, juice, milk</Breakfast>
<Lunch>meat sauce w/WG pasta, green beans, caesar salad, WW garlic toast, fruit, juice, milk</Lunch>
<Date>2/6/2013</Date>
<Breakfast>WG biscuit with chicken patty, fruit, juice, milk</Breakfast>
<Lunch>WG pizza, spinach salad, WKcorn, fruit, juice, milk</Lunch>
<Date>2/7/2013</Date>
<Breakfast>WG french toast sticks (4), sausage links, fruit, juice, milk</Breakfast>
<Lunch>salisbury steak, black eyed peas, creamed potatoes with gravy, greens-MC, spring mixed salad, WW cornbread, fruit, juice, milk</Lunch>
<Date>2/8/2013</Date>
<Breakfast>WG breakfast bagel, yogurt, fruit, juice, milk</Breakfast>
<Lunch>BBQ rib portion on WG bun, sweet potato fries or yams, romaine garden salad, fruit, juice, milk</Lunch>
<Date>2/11/2013</Date>
<Breakfast>Mardi Gras Holiday - No School</Breakfast>
<Lunch/>
</Content>
私は次のコードを使用しています:
StringBuilder sb=new StringBuilder(arg0[0]);
String findlink=sb.toString();
try{
HttpClient client=new DefaultHttpClient();
HttpGet request=new HttpGet();
request.setURI(new URI(findlink)) ;
HttpResponse response=client.execute(request);
//et.setText("its working");
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder Builder=factory.newDocumentBuilder();
dom=Builder.parse(response.getEntity().getContent());
dom.getDocumentElement().normalize();
nList5=dom.getElementsByTagName("Content");
for(int temp=0;temp<nList5.getLength();temp++)
{
Node nNode=nList5.item(temp);
if(nNode.getNodeType()==Node.ELEMENT_NODE)
{
Element eElement=(Element)nNode;
String base1 =getTagValue("Date",eElement);
Date.add(base1);
String base2 =getTagValue("Breakfast",eElement);
Breakfast.add(base2);
String base3 =getTagValue("Lunch",eElement);
Lunch.add(base3);
}
}
content.helpの下のすべてのタグを解析する方法これを行うのに役立ちます。