java add xmlns attribute

Solutions on MaxInterview for java add xmlns attribute by the best coders in the world

showing results for - "java add xmlns attribute"
Arsène
15 Mar 2019
1element.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:acme", "http://www.acme.com/schemas");
Juan
26 May 2020
1//Crear un document XML vacío
2DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
3dbfac.setNamespaceAware(true);
4DocumentBuilder docBuilder;
5docBuilder = dbfac.newDocumentBuilder();
6DOMImplementation domImpl = docBuilder.getDOMImplementation();
7Document doc = domImpl.createDocument("http://cancelacfd.sat.gob.mx", "Cancelacion", null);
8doc.setXmlVersion("1.0");
9doc.setXmlStandalone(true);
10
11Element cancelacion = doc.getDocumentElement();
12cancelacion.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xsd","http://www.w3.org/2001/XMLSchema");
13cancelacion.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
14cancelacion.setAttribute("RfcEmisor", rfc);
15cancelacion.setAttribute("Fecha", fecha);
16
17Element folios = doc.createElement("Folios");
18cancelacion.appendChild(folios);
19for (int i=0; i<uuid.length; i++) {
20    Element u = doc.createElement("UUID");
21    u.setTextContent(uuid[i]);
22    folios.appendChild(u);
23}