Forum Discussion

walkerline117's avatar
walkerline117
Contributor
8 years ago
Solved

Value of xml string output by xml generator snap cannot be replaced

Hi,

I m trying to use replace function in a mapper to replace some of the value in a xml string output by xml generator snap.
Something like below:

$xml.replace(‘<?xml version="1.0" encoding="UTF-8"?>’,‘’)
or
$xml.replace(‘no data’,‘’)

but it seems the replace function don’t work at all.

any help?

Thanks

  • For me,
    $xmlTest.replace('<?xml version="1.0" encoding="UTF-8"?>','')
    is returning
    "replaceTest": ""

    Is this not what you are expecting?

2 Replies

  • dmiller's avatar
    dmiller
    Former Employee

    For me,
    $xmlTest.replace('<?xml version="1.0" encoding="UTF-8"?>','')
    is returning
    "replaceTest": ""

    Is this not what you are expecting?

  • del's avatar
    del
    Contributor III

    @walkerline117, replace() is case-sensitive, so I’d check the letter casing in your usage since both “UTF-8” and “utf-8” are valid in the XML prolog.

    When using the replace() method, I prefer the slash over the single quote so I can add the optional flags. For instance: $xml.replace(/<?xml version="1.0" encoding="UTF-8"?>/i,'') is ignores case and should match either situation. Also $xml.replace(/no data/gi,'') should both ignore case and globally replace throughout the string rather than just replace the first match.