yuvaraj
yuvaraj

Reputation: 95

Read and modify XML data using JavaScript

I'm having XML file I want to read and modify XML data using JavaScript, this is my XML data:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<figlist>
  <figgroup name="Circuit Diagram">
    <category  id="A">
      <name>A GENERAL INFORMATION</name>
      <subcategory name="GI  GENERAL INFORMATION">
        <fig id="jtawa5397gb">
          <name>CONSULT CHECKING SYSTEM</name>
          <svgfile>jtawa5397gb.svg</svgfile>
        </fig>
      </subcategory>
    </category >

In this XML data CONSULT CHECKING SYSTEM I want to modify what ever contents inside tag by reading csv file data

For example in CSV file data it will have

CONSULT CHECKING SYSTEM CONSULTAR EL SISTEMA DE CONTROL

like this contents inside the tag it should change according Csv file data, I need to your help to modify this content through JavaScript.

Upvotes: 5

Views: 23896

Answers (1)

Sebastian
Sebastian

Reputation: 1820

If you are using the JavaScript environment of a modern web browser, you can manipulate XML data as I explained here: Create XML in Javascript

If not, I recommend to use another XML DOM implementation for JavaScript, for example xmldom.

Let's suppose, xmlDoc is your XML document as an XML DOM object. To change the text CONSULT CHECKING SYSTEM to CONSULT CHECKING SYSTEM CONSULTAR EL SISTEMA DE CONTROL, you could retrieve the element node like this:

var name = xmlDoc.getElementsByTagName("name")[1];

and change the content like this:

name.textContent = "CONSULT CHECKING SYSTEM CONSULTAR EL SISTEMA DE CONTROL";

Upvotes: 6

Related Questions