Question

My Android app reads a XML file and searches for a tag that can be found in different forms, like "tag" or "abc:tag" for example. My code is able to find just the "tag" form. How to find other forms? (wildcards?)

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
...
...
NodeList nodeList = root.getElementsByTagName("tag");
Was it helpful?

Solution

The solution is to use a similar method: getElementsByTagNameNS(String namespaceURI,String localName) with special "*" namespace

...
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
...
NodeList nodelist=root.getElementsByTagNameNS("*","tag");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top