cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

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

walkerline117
Contributor

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

1 ACCEPTED SOLUTION

dmiller
Admin Admin
Admin

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

Is this not what you are expecting?


Diane Miller
Community Manager

View solution in original post

2 REPLIES 2

dmiller
Admin Admin
Admin

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

Is this not what you are expecting?


Diane Miller
Community Manager

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.