Hi All,
i am having an issue with parser while my xml data contains invalid characters ( like '&' ) ....
i have this requirement that customer data may contain these sort of characters in any place/location of xml ..... we need to process them.
tried using CDATA but ineffective... will appreciate help from gurus on this site...
Thanks,
Shahid
CDATA should work. Do you have an example?
http://www.tibcommunity.com/message/36129#36129 has a working example of adding CDATA to cope with '&'
Thanks Tom ... but in your case, you are aware that those speacial characters will be in only one tag (residenceBuildingName) ....
and in my case, xml may have multiple incidents for this speacial character in multiple tags ........
i have attached my xml which is getting parsing error ....
I had faced a similar issue earlier and the solution we applied was a replaceAll custom java function.
Before parsing, we replaced all occurrences of & with & named entity and then parsed the string.
Regards ~ Yeshodhan
If you add CDATA block it should get parsed.
Please find attached a sample POC on how to add the CDATA in BW and get it parsed successfully.
If you dont want to use CDATA block just want to pass individual strings you can just use a render-xml activity in between and then pass the render-xm string to the parse-xml activity.
Hi Shahid,
Are you being asked to work around a defect in an existing system, or is it a theoretical requirement (i.e., the system is yet to be build, but the customer wants your stuff to be "robust")?
If it is the latter, then you should remind the powers that be that any interaction between two systems should have a interface contract that both teams have negotiated and agree to. Point out to them that without interface contracts you will have defects caused by misunderstandings between the teams, that no level of safe guards (like the ability to handle arbitrary '&' characters) will prevent. Once everyone agree's that an interface contract is required, then negotiate with the other team that they must provide you with valid XML. Anything less and you may as well bend over.
Hi Yeshodhan,
You've got to be careful with blanket '&' replacements as well. I remember having to deal with a system where sometimes you would get named entities, like '<' and other times you would get '&'.
yes Tom i do agree with you that the third party should send a valid xml and search and replace does have its limitation and also it effects the design
You can use biterscripting for parsing XML with special characters.
A sample XML:
<expression>
<type>arithmetic</type>
<syntax>(X+Y)</syntax>
</expression>
<expression>
<type>boolean</type>
<syntax>((X+Y)<(Z+3))&&(3>A)</syntax>
</expression>
Sample biterscripting code to get the <syntax>es from the above sample XML:
var str xml, node
cat "http://www.abc_xyz.com/path/to/file.xml" > $xml
while ( { sen -r -c "<syntax&\>&</syntax&\>" $xml } > 0 )
do
# Get <syntax...>...</syntax...>
stex -r -c "^<syntax&\>&</syntax&\>^" $xml > $node
# Strip off <syntax...>
stex -r -c "^<syntax&\>^]" $node > null
# Strip off </syntax...>
stex -r -c "[^</syntax&\>^" $node > null
# Display $node
echo $node
done
Will display
(X+Y)
((X+Y)<(Z+3))&&(3>A)
