You can put the xml file path here and keep parsing the inner nodes usiln self running loop. Save the values in arrays accordingly for each node..
NodeList eNodeList = null;
eNodeList = Utils.getXMLFromFilePath(your.xml", "firstNOdeNAme", eNodeList);
getElementsByNodelist(eNodeList)
private static getElementsByNodelist(Nodelist nodelist)
{
if(nodelist!=null)
{
for(int i = 0;i<nodelist.getLength();i++)
{
Element element = (Element) nodelist.item(i);
String id=getTextValue(element, "id");
//For attribute value
element.getAttribute("attributename");
// if u want to parse tjis element again
NodeList l=element.getElementsByTagName("innerTag");
// self loop
getElementsByNodelist(l);
}
}
}
public static String getTextValue(Element ele, String tagName) {
String textVal = "";
NodeList nl = ele.getElementsByTagName(tagName);
if(nl != null && nl.getLength() > 0) {
Element el = (Element)nl.item(0);
if(el.getFirstChild()!=null)
{
textVal = el.getFirstChild().getNodeValue();
}
}
return textVal;
}
그것은 작동하지 않습니다와
InputSource is = new InputSource(getResources().openRawResource(R.raw.example));
및 라인
xr.parse(new InputSource(sourceUrl.openStream()));
와 라인 URLsourceUrl = new URL ("example.com/w...";);
교체 (나는 삭스는 XML 파서로 사용)? 그것을 포착하십시오, 어떻게됩니까? –줄 바꾸기 URL sourceUrl = 새 URL ("http : //www.example.com/w ..."); with InputSource is = 새 InputSource (getResources(). openRawResource (R.raw.example)); 및 행 xr.parse (새 InputSource (sourceUrl.openStream())); 과 xr.parse (새 InputSource (is.getByteStream())); – giusepe
@ user1514941, 귀하의 의견을 읽을 수 없습니다. 코드 줄을 추가하거나 가능한 경우 전체 응용 프로그램 코드를 추가하여 질문을 편집하십시오. – Egor