Android Java XML : how to find tag like "abc:tag" with unknown "abc" part with getElementsByTagName()

StackOverflow https://stackoverflow.com/questions/20708566

문제

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");
도움이 되었습니까?

해결책

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");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top