Crear documento XML usando nodeList
Necesito crear un objeto de documento XML usando NodeList. ¿Puede alguien ayudarme a hacer esto? Te he mostrado el código y el xml debajo de
import
javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.*; import
org.w3c.dom.*;
public class ReadFile {
public static void main(String[] args) {
String exp = "/configs/markets";
String path = "testConfig.xml";
try {
, Document xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(path);
XPath xPath = XPathFactory.newInstance().newXPath();
XPathExpression xPathExpression = xPath.compile(exp);
NodeList nodes = (NodeList)
xPathExpression.evaluate(xmlDocument,
XPathConstants.NODESET);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
l archivo @xml se muestra debajo de
<configs>
<markets>
<market>
<name>Real</name>
</market>
<market>
<name>play</name>
</market>
</markets>
</configs>
Gracias por adelantado.