XML Pullparser: Getting The Value of a Particular node - android

Lets say I have a XML file:
<catalog>
<book>
<isbn>1</isbn>
<author> A</author>
<title>Title A</title>
<description> Desc A</description>
</book>
<book>
<isbn>2</isbn>
<author>B</author>
<title>Title B</title>
<description>Desc B</description>
</book>
...
<catalog>
As per Android's documentation I can fetch all the data in my Activity like this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
stringXmlContent = getEventsFromAnXML(this);
...
}
private String getEventsFromAnXML(Activity activity)
throws XmlPullParserException, IOException {
StringBuffer stringBuffer = new StringBuffer();
Resources res = activity.getResources();
XmlResourceParser xpp = res.getXml(R.xml.myxmlfile );
xpp.next();
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
stringBuffer.append("\nSTART_TAG: " + xpp.getName());
} else if (eventType == XmlPullParser.END_TAG) {
stringBuffer.append("\nEND_TAG: " + xpp.getName());
} else if (eventType == XmlPullParser.TEXT) {
stringBuffer.append("\nTEXT: " + xpp.getText());
}
eventType = xpp.next();
}
return stringBuffer.toString();
}
While this fetches all content from XML file, I am really struggling to filter it out for a certain condition.
For example let us say I want to get the author name for book with isbn of 2. How do I filter this data out using pullparser ?

check this out and modify according to your needs
URL url2 = new URL("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=" +artist+ "&api_key=1732077d6772048ccc671c754061cb18");
URLConnection connection = url2.openConnection();
connection.setConnectTimeout(10000);
connection.setReadTimeout(30000);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
final Document document = db.parse(connection.getInputStream());
document.getDocumentElement().normalize();
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xPathEvaluator = xPathfactory.newXPath();
XPathExpression nameExpr = xPathEvaluator.compile("//lfm/artist/image");
// XPathExpression nameExpr = xPathEvaluator.compile("//lfm/tracks/track/image");
NodeList nl = (NodeList) nameExpr.evaluate(document, XPathConstants.NODESET);
for (int zzz = 0; zzz < nl.getLength(); zzz++)
{
Node currentItem = nl.item(zzz);
key = currentItem.getTextContent();
// key = currentItem.getAttributes().getNamedItem("uri").getNodeValue();
}
in the variable key,i get the value of the node which contains image

It requires a bit of guess and check (at least that's what I needed when I did it), but you can easily test a certain node's text to see if the ISBN is 2 (and, if it is, you can continue to parse the data. Otherwise, you can keep going until you get to the next ISBN node.

Related

Android Studio XmlPullParser parsing multiply nested elements

My XML file is something like this:
<Items>
<Nested_item>
<id>1</id>
<name>nested</name>
<description>
<desc_item>1</desc_item>
<desc_item>2</desc_item>
<desc_item>3</desc_item>
</description>
</Nested_item>
<Nested_item>
<id>2</id>
<name>nested2</name>
<description>
<desc_item>1</desc_item>
<desc_item>2</desc_item>
<desc_item>3</desc_item>
</description>
</Nested_item>
<Nested_item>
<id>3</id>
<name>nested3</name>
<description>
<desc_item>1</desc_item>
<desc_item>2</desc_item>
<desc_item>3</desc_item>
</description>
</Nested_item>
</Items>
and I have class Items with atributes which I've putted into ArrayList, I've managed to parse all atributes except desc_item (which I need as ArrayList for every Item object). How can I tell parser to take only third item, for example, and to get those desc_item values as String?
I found solution to my problem, i have parsed inner data and after that i have parsed particular data:
private ArrayList<Proizvod> parseXML (XmlPullParser parser) throws XmlPullParserException, IOException {
ArrayList<Proizvod> proizvodLista = null;
int eventType = parser.getEventType();
Proizvod proizvod = null;
while(eventType != XmlPullParser.END_DOCUMENT){
String name;
switch (eventType){
case XmlPullParser.START_DOCUMENT:
proizvodLista = new ArrayList<Proizvod>();
break;
case XmlPullParser.START_TAG:
name = parser.getName();
//System.out.println(name);
if(name.equals("Proizvod")){
proizvod = new Proizvod();
proizvod.setId(parser.getAttributeValue(null, "id"));
}else if(proizvod != null){
if(name.equalsIgnoreCase("ime_proizvoda")){
proizvod.setIme_proizvoda(parser.nextText());
}else if(name.equalsIgnoreCase("vrsta_proizvoda")){
proizvod.setVrsta_proizvoda(parser.nextText());
}else if(name.equalsIgnoreCase("merna_jedinica")){
proizvod.setVrsta_proizvoda(parser.nextText());
}else if(name.equalsIgnoreCase("Prodavnice")){
proizvod.setLista_prodavnica(parsing(parser));
}
}
break;
case XmlPullParser.END_TAG:
name = parser.getName();
if(name.equalsIgnoreCase("proizvod")&& proizvod !=null){
proizvodLista.add(proizvod);
}
}
eventType = parser.next();
}
return proizvodLista;
}
private ArrayList<String> parsing (XmlPullParser parser) throws XmlPullParserException, IOException {
String print = null;
int eventType = parser.getEventType();
ArrayList<String> lista = new ArrayList<String>();
while(eventType != XmlPullParser.END_DOCUMENT){
String name = parser.getName();
if(name.equalsIgnoreCase("Prodavnice")){break;}
else{
if(eventType==XmlPullParser.START_TAG){
print = parser.nextText();
lista.add(print);
System.out.println(print);
}
}
eventType = parser.next();
}
return lista;
}
And my XML looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Proizvodi>
<Proizvod id="1">
<ime_proizvoda>Mleko</ime_proizvoda>
<vrsta_proizvoda>mlecni proizvod</vrsta_proizvoda>
<merna_jedinica>litar</merna_jedinica>
<Prodavnice>
<Prodavnica>1</Prodavnica>
<Prodavnica>3</Prodavnica>
<Prodavnica>4</Prodavnica>
</Prodavnice>
</Proizvod>
<Proizvod id="2">
<ime_proizvoda>Hleb</ime_proizvoda>
<vrsta_proizvoda>Pekarski proizvod</vrsta_proizvoda>
<merna_jedinica>gram</merna_jedinica>
<Prodavnice>
<Prodavnica>1</Prodavnica>
<Prodavnica>2</Prodavnica>
<Prodavnica>3</Prodavnica>
</Prodavnice>
</Proizvod>
<Proizvod id="3">
<ime_proizvoda>Suvi vrat</ime_proizvoda>
<vrsta_proizvoda>Mesna preradjevina</vrsta_proizvoda>
<merna_jedinica>gram</merna_jedinica>
<Prodavnice>
<Prodavnica>2</Prodavnica>
<Prodavnica>3</Prodavnica>
<Prodavnica>4</Prodavnica>
</Prodavnice>
</Proizvod>
<Proizvod id="4">
<ime_proizvoda>Pecenica</ime_proizvoda>
<vrsta_proizvoda>Mesna preradjevina</vrsta_proizvoda>
<merna_jedinica>100 grama</merna_jedinica>
<Prodavnice>
<Prodavnica>1</Prodavnica>
<Prodavnica>2</Prodavnica>
<Prodavnica>4</Prodavnica>
</Prodavnice>
</Proizvod>

traverse nested xml file android

I'm trying to traverse a nested XML string in Android that looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Results>
<Result>
<Questions>
<Question>Where can I get the local variable</Question>
<Answer>In the local method</Answer>
<AverageRating>3.0</AverageRating>
</Questions>
<Keywords>
<Keyword>Methods</Keyword>
<Keyword>Returns</Keyword>
<Keyword>Void</Keyword>
</Keywords>
</Result>
<Result>
<Questions>
<Question>How can I do a nested for loop</Question>
<Answer>Easy</Answer>
<AverageRating>2.5</AverageRating>
</Questions>
<Keywords>
<Keyword>Methods</Keyword>
<Keyword>Returns</Keyword>
<Keyword>Void</Keyword>
<Keyword>Methods</Keyword>
<Keyword>Returns</Keyword>
</Keywords>
</Result>
with the following Android code:
try
{
//Creates the document
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(serverResult)));
//optional, but recommended
//read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
document.getDocumentElement().normalize();
//Look at root node's type (e.g. <query> or <login> or <add>)
String rootNode = document.getDocumentElement().getNodeName().toString();
if (rootNode.equals("Results"))
{
String Question = "";
String Answer = "";
String AverageRating = "";
float rating = 0;
String keyword = "";
NodeList nList = document.getElementsByTagName("Result");
for (int i = 0; i < nList.getLength(); i++)
{
Node nodes = nList.item(i);
if (nodes.getNodeType() == Node.ELEMENT_NODE)
{
Element element = (Element) nodes;
NodeList list = document.getElementsByTagName("Questions");
for (int value = 0; value < list.getLength(); value++)
{
Node node = list.item(value);
if (node.getNodeType() == Node.ELEMENT_NODE)
{
Element eElement = (Element) node;
Question = getValue("Question", eElement);
Answer = getValue("Answer", eElement);
AverageRating = getValue("AverageRating", eElement);
rating = Float.parseFloat(AverageRating);
}
}
}
NodeList keywordNode = document.getElementsByTagName("Keywords");
String keywords = "";
for (int y = 0; y < keywordNode.getLength(); y++)
{
Node node = keywordNode.item(y);
if (node.getNodeType() == Node.ELEMENT_NODE)
{
Element element = (Element) node;
NodeList ModList = document.getElementsByTagName("Keyword");
int count = ModList.getLength();
for (int b = 0; b < count; b++)
{
keyword = element.getElementsByTagName("Keyword").item(b).getTextContent();
keywords = keywords + keyword + "\n";
}
}
items.add(new Question(Question, Answer, rating, keywords));
}
}
}
}
catch (Exception e)
{
String s = e.getMessage();
publishProgress(s);
}
What I'm trying to achieve is for each question of each respective results in the Result tag of my XML, I want to get the question (and it's details) and the respective keywords, adding each to the Question class, then repeat for the next result from Results tag. Can someone please help with my code and show me where I'm going wrong?
Try importing these:
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
by downloading them at this site: http://www.xmlpull.org/
Then, try a code structure like this:
String XMLin;
XmlPullParserFactory factory;
String tag;
ArrayList<Question> questions = new ArrayList<Question>();
try {
XMLin = readString(instream);
} catch (IOException e1) {
// TODO Auto-generated catch block
XMLin = "Something went wrong";
}
try {
// Set up the Class that will be parsing the xml file
factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new StringReader (XMLin));
// Get the first event type
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
// While we have not reached the end of the document, check for start tags
if (eventType == XmlPullParser.START_TAG) {
tag = xpp.getName();
if (tag.equals("Questions") && eventType == XmlPullParser.START_TAG) {
Question question = new Question();
do {
if (tag.equals("Question")) {
// Add question text to question
eventType = xpp.next();
String text = xpp.getText(); // Text between tags
} else if (tag.equals("Answer")) {
eventType = xpp.next();
String text = xpp.getText(); // Text between tags
} else if (tag.equals("AvergaeRating") {
eventType = xpp.next();
String text = xpp.getText(); // Text between tags
}
eventType = xpp.next();
if (eventType == XmlPullParser.TEXT) {
tag = xpp.getText();
} else {
tag = xpp.getName();
}
} while (!tag.equals("Questions"))
questions.add(question);
}
}
}
This is a modified example of something I used to parse through XML. Essentially, check for the tag name and event (whether it's a start tag or end tag, etc) and then perform that actions you want depending on those two values, such as add the text inbetween into a Question object or whatnot.
I managed to use this code:
try
{
//Creates the document
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(serverResult)));
//optional, but recommended
//read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
document.getDocumentElement().normalize();
//Look at root node's type (e.g. <query> or <login> or <add>)
String rootNode = document.getDocumentElement().getNodeName().toString();
if (rootNode.equals("Results"))
{
//Any methods which need to be called that will be used to query the database
//Always sending the String XML through as a parameter
//Look at the child node
String Question = "";
String Answer = "";
String AverageRating = "";
float rating = 0;
String keywords = "";
NodeList nList = document.getElementsByTagName("Questions");
System.out.println("----------------------------");
for (int temp = 0; temp < nList.getLength(); temp++)
{
Node nNode = nList.item(temp);
System.out.println("\nCurrent Element :" + nNode.getNodeName());
if (nNode.getNodeType() == Node.ELEMENT_NODE)
{
Element eElement = (Element) nNode;
Question = getValue("Question", eElement);
Answer = getValue("Answer", eElement);
AverageRating = getValue("AverageRating", eElement);
rating = Float.parseFloat(AverageRating);
NodeList List = document.getElementsByTagName("Keywords");
for (int a = 0; a < List.getLength(); a++)
{
Node node = List.item(temp);
if (node.getNodeType() == Node.ELEMENT_NODE)
{
Element element = (Element) node;
String Keyword = element.getElementsByTagName("Keyword").item(0).getTextContent();
keywords = keywords + Keyword + "\n";
}
}
}
items.add(new Question(Question, Answer, rating, keywords));
}
}
}
catch (IOException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
which then get's each individual question (and all their information - question, answer, rating) and well as the respective keywords for that question and add to a Question object, then loop back. I wasn't putting the keywords XML parse within the questions for loop. Hopefully this helps someone who is struggling with similar problems.

How to scroll webview in Google Glass

I have an Rss feed app displaying title and description from xml. I'm parsing the xml and displaying the content inside webview. When i navigate to webview, i can't able to scroll the content. It's like static. Is there is way to scroll content inside webview?
webview:
title = (TextView) findViewById(R.id.title);
desc = (WebView) findViewById(R.id.desc);
// set webview properties
WebSettings ws = desc.getSettings();
ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
ws.getPluginState();
ws.setPluginState(PluginState.ON);
ws.setJavaScriptEnabled(true);
ws.setBuiltInZoomControls(true);
// Set the views
title.setText(feed.getItem(pos).getTitle());
desc.loadDataWithBaseURL("http://www.googleglass.gs/", feed
.getItem(pos).getDescription(), "text/html", "UTF-8", null);
Parsing:
public class DOMParser {
private RSSFeed _feed = new RSSFeed();
public RSSFeed parseXml(String xml) {
URL url = null;
try {
url = new URL(xml);
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
try {
// Create required instances
DocumentBuilderFactory dbf;
dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
// Parse the xml
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
// Get all <item> tags.
NodeList nl = doc.getElementsByTagName("item");
int length = nl.getLength();
for (int i = 0; i < length; i++) {
Node currentNode = nl.item(i);
RSSItem _item = new RSSItem();
NodeList nchild = currentNode.getChildNodes();
int clength = nchild.getLength();
// Get the required elements from each Item
for (int j = 1; j < clength; j = j + 2) {
Node thisNode = nchild.item(j);
String theString = null;
String nodeName = thisNode.getNodeName();
theString = nchild.item(j).getFirstChild().getNodeValue();
if (theString != null) {
if ("title".equals(nodeName)) {
// Node name is equals to 'title' so set the Node
// value to the Title in the RSSItem.
_item.setTitle(theString);
}
else if ("content:encoded".equals(nodeName)) {
_item.setDescription(theString);
// Parse the html description to get the image url
String html = theString;
org.jsoup.nodes.Document docHtml = Jsoup
.parse(html);
Elements imgEle = docHtml.select("img");
_item.setImage(imgEle.attr("src"));
}
else if ("pubDate".equals(nodeName)) {
// We replace the plus and zero's in the date with
// empty string
String formatedDate = theString.replace(" +0000",
"");
_item.setDate(formatedDate);
}
}
}
// add item to the list
_feed.addItem(_item);
}
} catch (Exception e) {
}
// Return the final feed once all the Items are added to the RSSFeed
// Object(_feed).
return _feed;
}
}
You have to implement your own WebView and implement that functionality or you can use Native Google Glass WebBrowser with an Intent.
EDIT: You also can try to use native webBrowser with an intent:
Intent intent = new Intent(Intent.ACTION_VIEW);
String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString());
String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
intent.setClassName("com.google.glass.browser", "com.google.glass.browser.WebBrowserActivity");
intent.setDataAndType(Uri.fromFile(file),mimetype);
startActivity(intent);
You create a HTML file with the content of your XML, you save it in the sdcard and then you open it with Intent.

android xml file modifying

I receive a XML string from server that is structured like this:
<item_list>
<category>
<item id="1" name="name1" base64="base64String1" />
<item id="2" name="name2" base64="base64String2" />
<item id="3" name="name3" base64="base64String3" />
<item id="4" name="name4" base64="base64String4" />
........
</category>
<category>
........
</category>
<item_list>
What I need to do is this: when I first read the string, read the Base64 strings, save them in a file and then remove them from this string. And then write this string to a XML file. So after that this XML will look like:
<item_list>
<category>
<item id="1" name="name1" />
<item id="2" name="name2" />
<item id="3" name="name3" />
<item id="4" name="name4" />
........
</category>
<category>
........
</category>
<item_list>
Which parser show I use for reading and deleting the Base64 strings? which is the best for this?
And if someone could give me an example or a tutorial how to do this, it would be great.
You can use XPath for that with the expression query "//*[#base64]".
try {
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(true);
DocumentBuilder builder = builderFactory.newDocumentBuilder();
Document document = builder.parse(new File("your_xml.xml"));
XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "//*[#base64]";
NodeList nodes = (NodeList) xpath.evaluate(expression, document, XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
String base64 = element.getAttribute("base64");
element.removeAttribute("base64");
}
String newXML = getStringFromNode(document);
}
catch (Exception e) {
}
getStringFromNode method
public static String getStringFromNode(Node root) {
StringBuilder result = new StringBuilder();
if (root.getNodeType() == 3)
result.append(root.getNodeValue());
else {
if (root.getNodeType() != 9) {
StringBuffer attrs = new StringBuffer();
for (int k = 0; k < root.getAttributes().getLength(); ++k) {
attrs.append(" ").append(
root.getAttributes().item(k).getNodeName()).append(
"=\"").append(
TextUtils.htmlEncode(root.getAttributes().item(k).getNodeValue()))
.append("\" ");
}
result.append("<").append(root.getNodeName()).append(" ")
.append(attrs).append(">");
} else {
result.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
}
NodeList nodes = root.getChildNodes();
for (int i = 0, j = nodes.getLength(); i < j; i++) {
Node node = nodes.item(i);
result.append(getStringFromNode(node));
}
if (root.getNodeType() != 9) {
result.append("</").append(root.getNodeName()).append(">");
}
}
return result.toString();
}
EDITED
The same could be used for parsing the String also. See my method below which will parse the String as DOM Document. Now you can use this Document as input for your XPath.
public static Document ReadDocument(String xml)
{
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
StringReader reader = new StringReader(xml);
is.setCharacterStream(reader);
doc = db.parse(is);
} catch (Exception e) {
Log.e("Error", "Error while Parsing Document", e);
return null;
}
return doc;
}
Minor improvements for Vivek's function -> Handle CDATA + Use field constants:
public static String getStringFromNode(Node root) throws IOException
{
StringBuilder result = new StringBuilder();
if (root.getNodeType() == Node.TEXT_NODE)
result.append(root.getNodeValue());
else if(root.getNodeType() == Node.CDATA_SECTION_NODE)
result.append("<![CDATA["+root.getNodeValue()+"]]>");
else {
if (root.getNodeType() != Node.DOCUMENT_NODE) {
StringBuffer attrs = new StringBuffer();
for (int k = 0; k < root.getAttributes().getLength(); ++k) {
attrs.append(" ").append(
root.getAttributes().item(k).getNodeName()).append(
"=\"").append(
root.getAttributes().item(k).getNodeValue())
.append("\" ");
}
result.append("<").append(root.getNodeName()).append(" ")
.append(attrs).append(">");
} else {
result.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
}
NodeList nodes = root.getChildNodes();
for (int i = 0, j = nodes.getLength(); i < j; i++) {
Node node = nodes.item(i);
result.append(getStringFromNode(node));
}
if (root.getNodeType() != Node.DOCUMENT_NODE) {
result.append("</").append(root.getNodeName()).append(">");
}
}
return result.toString();
}

how to get inner content of xml in android?

how to get inner content of xml in android?
For example if the
I have used following code but it does not return actual result..
String xml ="<hello><hai>welcome<hai></hello>";
InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(is);
String response = document.getElementsByTagName("hello");
I need the result "<hai>welcome<hai>"..Thanks in advance
i had the same problem and i did this:
i made 2 functions, getxml() checks if there are child nodes
and xmltagswtf() returns the rest of code
public String getxml(Node b){
String va = "";
if (b.hasChildNodes()==true){
int nodes = 0;
int a=b.getChildNodes().getLength();
while (nodes <a){
Node c = b.getChildNodes().item(nodes);
if(c.getNodeName()!="#text"){
va+="<"+c.getNodeName()+">"+getxml(c)+"</"+c.getNodeName()+">";
}else{
va+=getxml(c);
}nodes+=1;
}
}else{va=b.getTextContent();}
return va;
}
public String xmltagswtf(String xmlt, String what) throws SAXException, IOException, ParserConfigurationException{
InputStream is = new ByteArrayInputStream(xmlt.getBytes("UTF-8"));
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(is);
NodeList response = document.getElementsByTagName(what);
Node nod = response.item(0);
String nodos = "";
if (nod.hasChildNodes()==true){
int nodes = 0;
int a=nod.getChildNodes().getLength();
while (nodes <a){
Node c = nod.getChildNodes().item(nodes);
nodos+="<"+c.getNodeName()+">"+getxml(c)+"</"+c.getNodeName()+">";
nodes+=1;
}
}else{
nodos+=nod.getTextContent();
System.out.println(nodos);
}
return nodos;
}
then do something like this:
String xml ="<hello><hai>welcome</hai></hello>";
String hai =xmltagswtf(xml, "hello");

Categories

Resources