Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Delete a node in XML

Avatar

Level 2

Hi

I have a XML that is getting generated on click of a button in the form.

I am using  xfa.data.saveXML("pretty"); to generate the XML.

Following is the XML,

<?xml version="1.0" encoding="UTF-8"?>

<xfa:data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">

   <ELEMENT>

      <DATA>

         <ROW_IID>0</ROW_IID>

         <PARENT>0</PARENT>

         <CHILD>0</CHILD>

      </DATA>

      <NAME> 

          <FNAME>0</FNAME>

          <LNAME>0</LNAME>

      </NAME>

   </ELEMENT>

</xfa:data>

I want to delete the <NAME> node in the XML and assign the manipulated XML to some text field.

Could anyone please let me know how to do the same?

Thanks:)

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Considering you want the output as a string you could use XSLT, so something like (which copies all xml nodes except the NAME one);

var stylesheet =

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method = "xml" omit-xml-declaration = "yes" indent = "yes"/>   

        <xsl:template match="@*|node()">

            <xsl:copy>

                <xsl:apply-templates select="@*|node()"/>

            </xsl:copy>

        </xsl:template>

        <xsl:template match="NAME"/>

    </xsl:stylesheet>

var txt = $data.ELEMENT.applyXSL(stylesheet.toXMLString());    

console.println(txt)

You could also use;

$data.ELEMENT.nodes.remove($data.ELEMENT.NAME)

console.println($data.ELEMENT.saveXML("pretty"));

Regards

Bruce

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

Considering you want the output as a string you could use XSLT, so something like (which copies all xml nodes except the NAME one);

var stylesheet =

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method = "xml" omit-xml-declaration = "yes" indent = "yes"/>   

        <xsl:template match="@*|node()">

            <xsl:copy>

                <xsl:apply-templates select="@*|node()"/>

            </xsl:copy>

        </xsl:template>

        <xsl:template match="NAME"/>

    </xsl:stylesheet>

var txt = $data.ELEMENT.applyXSL(stylesheet.toXMLString());    

console.println(txt)

You could also use;

$data.ELEMENT.nodes.remove($data.ELEMENT.NAME)

console.println($data.ELEMENT.saveXML("pretty"));

Regards

Bruce

Avatar

Level 2

Hi Bruce,

Its working!!..Thanks you so much:-)