Foros del Web » Programación para mayores de 30 ;) » Java »

[SOLUCIONADO] Agregar líneas dinámicamente en un archivo XML

Estas en el tema de Agregar líneas dinámicamente en un archivo XML en el foro de Java en Foros del Web. Hola expertos, necesito agregar algunas líneas sobre un nuevo archivo XML, de manera dinámica. Archivo origen test.xml: Código: <?xml version="1.0" encoding="UTF-8"?> cns:Document xmlns:cns="smpcfg.xsd" DatabaseComment="Partial Export"> ...
  #1 (permalink)  
Antiguo 10/11/2017, 05:59
 
Fecha de Ingreso: octubre-2011
Ubicación: Merlo
Mensajes: 18
Antigüedad: 12 años, 5 meses
Puntos: 1
Busqueda Agregar líneas dinámicamente en un archivo XML

Hola expertos, necesito agregar algunas líneas sobre un nuevo archivo XML, de manera dinámica.
Archivo origen test.xml:
Código:
<?xml version="1.0" encoding="UTF-8"?>
cns:Document xmlns:cns="smpcfg.xsd" DatabaseComment="Partial Export">
  <Status NAME="D1" StatusType="D1, Normally closed, Event">
    <Bypass>false</Bypass>
    <ExternalName>BRIGHTON.CB.3940.D1</ExternalName>
  </Status>
  <Status NAME="D2" StatusType="D2, Normally closed, Event">
    <Bypass>false</Bypass>
    <ExternalName>BRIGHTON.CB.3940.D2</ExternalName>
  </Status>
</cns:Document>
las líneas que quiero agregar a cada elemento <Status>:
Código:
<Control NAME="Trip">
  <DeviceName>TRIP</DeviceName>
  <Timeout>60</Timeout>
</Control>
<Control NAME="Close">
  <DeviceName>CLOSE</DeviceName>
  <Timeout>60</Timeout>
</Control>
y el XML fina, con la lineas agregadas:
Código:
<?xml version="1.0" encoding="UTF-8"?>
cns:Document xmlns:cns="smpcfg.xsd" DatabaseComment="Partial Export">
  <Status NAME="D1" StatusType="D1, Normally closed, Event">
    <Bypass>false</Bypass>
    <ExternalName>BRIGHTON.CB.3940.D1</ExternalName>
        <Control NAME="Trip">
            <DeviceName>TRIP</DeviceName>
            <Timeout>60</Timeout>
        </Control>
            <Control NAME="Close">
              <DeviceName>CLOSE</DeviceName>
              <Timeout>60</Timeout>
        </Control>
  </Status>
  <Status NAME="D2" StatusType="D2, Normally closed, Event">
    <Bypass>false</Bypass>
    <ExternalName>BRIGHTON.CB.3940.D2</ExternalName>
       <Control NAME="Trip">
          <DeviceName>TRIP</DeviceName>
            <Timeout>60</Timeout>
        </Control>
        <Control NAME="Close">
              <DeviceName>CLOSE</DeviceName>
              <Timeout>60</Timeout>
        </Control>
  </Status>
</cns:Document>
Es decir, necesito agregar estas líneas para cada "estado".
¿Podrías darme una idea de como hacerlo con JAVA o directamente en XML?
Gracias
  #2 (permalink)  
Antiguo 12/11/2017, 18:49
Avatar de Fuzzylog  
Fecha de Ingreso: agosto-2008
Ubicación: En internet
Mensajes: 2.511
Antigüedad: 15 años, 7 meses
Puntos: 188
Respuesta: Agregar líneas dinámicamente en un archivo XML

Aquí tienes un punto de partida

https://stackoverflow.com/questions/...l-file-in-java
__________________
if (fuzzy && smooth) {
fuzzylog = "c00l";
return true;
}
  #3 (permalink)  
Antiguo 13/11/2017, 05:07
 
Fecha de Ingreso: octubre-2011
Ubicación: Merlo
Mensajes: 18
Antigüedad: 12 años, 5 meses
Puntos: 1
Respuesta: Agregar líneas dinámicamente en un archivo XML

Excelente, muchas gracias, es lo que necesitaba.
  #4 (permalink)  
Antiguo 13/11/2017, 06:03
Avatar de Fuzzylog  
Fecha de Ingreso: agosto-2008
Ubicación: En internet
Mensajes: 2.511
Antigüedad: 15 años, 7 meses
Puntos: 188
Respuesta: Agregar líneas dinámicamente en un archivo XML

__________________
if (fuzzy && smooth) {
fuzzylog = "c00l";
return true;
}

Etiquetas: java., xml
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:26.