Xml 解析媒体标签值未进入 android?
Xml parsing Media tag values not getting in android?
我正在实施 xml 解析,但是当我当时访问媒体标签时,图像值不是 displaying.i 已经实施此检查,下面的代码不适用于媒体 ID 和 url.you可以查看下图中的xml数据
public static final String X_PF_CONTENT_IMPORT="pf_content_import";
public static final String X_SPOT="spot";
public static final String X_ID="id";
public static final String X_VALID="valid";
public static final String X_TEXT="text";
public static final String X_HEADER="header";
public static final String X_BODY="body";
public static final String X_MEDIA="media";
public static final String X_IMAGE="image";
XmlParsing xparser= new XmlParsing();
String xml = xparser.getXmlFromUrl(url); // getting XML
Document doc = xparser.getDomElement(xml); // getting DOM element
NodeList nspot = doc.getElementsByTagName(X_SPOT);
Log.e("Nodename","--->"+nspot.getLength());
for(int i=0;i<nspot.getLength();i++){
Node n=nspot.item(i);
Element eLemenSpot = (Element)n;
String id=eLemenSpot.getAttribute(X_ID);
String valid=eLemenSpot.getElementsByTagName(X_VALID).item(0).getTextContent();
Log.e("Id","--->"+id);
Log.e("Valid","--->"+valid);
NodeList text=eLemenSpot.getElementsByTagName(X_TEXT);
Node ntext=text.item(0);
Element elementText=(Element)ntext;
String header=elementText.getElementsByTagName(X_HEADER).item(0).getTextContent();
String body=elementText.getElementsByTagName(X_BODY).item(0).getTextContent();
Log.e("Header","--->"+header);
Log.e("Body","--->"+body);
NodeList media=eLemenSpot.getElementsByTagName(X_MEDIA);
for(int k=0;k<media.getLength();k++){
Node nmedia=media.item(k);
Element elementMedia=(Element)nmedia;
String image_id=elementMedia.getAttribute("id");
String image_url=elementMedia.getElementsByTagName(X_IMAGE).item(k).getTextContent();
Log.e(" Media Id", "---->"+image_id);
Log.e("Media Url", "---->"+image_url);
}
}
Logcat
03-05 00:36:11.513: E/Nodename(14195): --->2
03-05 00:36:11.513: E/Id(14195): --->1
03-05 00:36:11.513: E/Valid(14195): --->2015-03-05T11:34:59.337278+01:00
03-05 00:36:11.523: E/Header(14195): --->OPTISCH GANZ VERÃNDERT
03-05 00:36:11.523: E/Body(14195): --->BACK TO THE ROOTS: MANDY CAPRISTO PUNKTET MIT DUNKLEN HAAREN
03-05 00:36:11.523: E/Media Id(14195): ---->
03-05 00:36:11.523: E/Media Url(14195): ---->http://content3.promiflash.de/article-images/infoscreen1/mandy-capristo-mit-dunklen-haaren.jpg
03-05 00:36:11.523: E/Id(14195): --->2
03-05 00:36:11.523: E/Valid(14195): --->2015-03-05T11:34:59.337278+01:00
03-05 00:36:11.523: E/Header(14195): --->OPTISCH GANZ VERÃNDERT
03-05 00:36:11.523: E/Body(14195): --->BACK TO THE ROOTS: MANDY CAPRISTO PUNKTET MIT DUNKLEN HAAREN
03-05 00:36:11.533: E/Media Id(14195): ---->
03-05 00:36:11.533: E/Media Url(14195): ---->http://content3.promiflash.de/article-images/infoscreen2/mandy-capristo-mit-dunklen-haaren.jpg
请试试这个
NodeList nodeList = document.getElementsByTagName("image");
for(int i=0,size= nodeList.getLength(); i<size; i++) {
Log.e("",nodeList.item(i).getAttributes().getNamedItem("id").getNodeValue());
Log.i("",nodeList.item(i).getTextContent());
}
我需要创建图像节点列表
NodeList media=eLemenSpot.getElementsByTagName(X_MEDIA);
for(int k=0;k<media.getLength();k++){
Node nmedia=media.item(k);
Element elementMedia=(Element)nmedia;
NodeList nimage=elementMedia.getElementsByTagName(X_IMAGE);
for(int j=0;j<nimage.getLength();j++){
Log.e(" Media Id", "---->"+nimage.item(j).getAttributes().getNamedItem(X_ID).getNodeValue());
Log.e("Media Url", "---->"+nimage.item(j).getTextContent());
}
}
我正在实施 xml 解析,但是当我当时访问媒体标签时,图像值不是 displaying.i 已经实施此检查,下面的代码不适用于媒体 ID 和 url.you可以查看下图中的xml数据
public static final String X_PF_CONTENT_IMPORT="pf_content_import";
public static final String X_SPOT="spot";
public static final String X_ID="id";
public static final String X_VALID="valid";
public static final String X_TEXT="text";
public static final String X_HEADER="header";
public static final String X_BODY="body";
public static final String X_MEDIA="media";
public static final String X_IMAGE="image";
XmlParsing xparser= new XmlParsing();
String xml = xparser.getXmlFromUrl(url); // getting XML
Document doc = xparser.getDomElement(xml); // getting DOM element
NodeList nspot = doc.getElementsByTagName(X_SPOT);
Log.e("Nodename","--->"+nspot.getLength());
for(int i=0;i<nspot.getLength();i++){
Node n=nspot.item(i);
Element eLemenSpot = (Element)n;
String id=eLemenSpot.getAttribute(X_ID);
String valid=eLemenSpot.getElementsByTagName(X_VALID).item(0).getTextContent();
Log.e("Id","--->"+id);
Log.e("Valid","--->"+valid);
NodeList text=eLemenSpot.getElementsByTagName(X_TEXT);
Node ntext=text.item(0);
Element elementText=(Element)ntext;
String header=elementText.getElementsByTagName(X_HEADER).item(0).getTextContent();
String body=elementText.getElementsByTagName(X_BODY).item(0).getTextContent();
Log.e("Header","--->"+header);
Log.e("Body","--->"+body);
NodeList media=eLemenSpot.getElementsByTagName(X_MEDIA);
for(int k=0;k<media.getLength();k++){
Node nmedia=media.item(k);
Element elementMedia=(Element)nmedia;
String image_id=elementMedia.getAttribute("id");
String image_url=elementMedia.getElementsByTagName(X_IMAGE).item(k).getTextContent();
Log.e(" Media Id", "---->"+image_id);
Log.e("Media Url", "---->"+image_url);
}
}
Logcat
03-05 00:36:11.513: E/Nodename(14195): --->2
03-05 00:36:11.513: E/Id(14195): --->1
03-05 00:36:11.513: E/Valid(14195): --->2015-03-05T11:34:59.337278+01:00
03-05 00:36:11.523: E/Header(14195): --->OPTISCH GANZ VERÃNDERT
03-05 00:36:11.523: E/Body(14195): --->BACK TO THE ROOTS: MANDY CAPRISTO PUNKTET MIT DUNKLEN HAAREN
03-05 00:36:11.523: E/Media Id(14195): ---->
03-05 00:36:11.523: E/Media Url(14195): ---->http://content3.promiflash.de/article-images/infoscreen1/mandy-capristo-mit-dunklen-haaren.jpg
03-05 00:36:11.523: E/Id(14195): --->2
03-05 00:36:11.523: E/Valid(14195): --->2015-03-05T11:34:59.337278+01:00
03-05 00:36:11.523: E/Header(14195): --->OPTISCH GANZ VERÃNDERT
03-05 00:36:11.523: E/Body(14195): --->BACK TO THE ROOTS: MANDY CAPRISTO PUNKTET MIT DUNKLEN HAAREN
03-05 00:36:11.533: E/Media Id(14195): ---->
03-05 00:36:11.533: E/Media Url(14195): ---->http://content3.promiflash.de/article-images/infoscreen2/mandy-capristo-mit-dunklen-haaren.jpg
请试试这个
NodeList nodeList = document.getElementsByTagName("image");
for(int i=0,size= nodeList.getLength(); i<size; i++) {
Log.e("",nodeList.item(i).getAttributes().getNamedItem("id").getNodeValue());
Log.i("",nodeList.item(i).getTextContent());
}
我需要创建图像节点列表
NodeList media=eLemenSpot.getElementsByTagName(X_MEDIA);
for(int k=0;k<media.getLength();k++){
Node nmedia=media.item(k);
Element elementMedia=(Element)nmedia;
NodeList nimage=elementMedia.getElementsByTagName(X_IMAGE);
for(int j=0;j<nimage.getLength();j++){
Log.e(" Media Id", "---->"+nimage.item(j).getAttributes().getNamedItem(X_ID).getNodeValue());
Log.e("Media Url", "---->"+nimage.item(j).getTextContent());
}
}