function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chandra2ravichandra2ravi 

XML parsing error

Hi,

I am getting following error while using the parse xml.

Exception

null Exception: Failed to parse XML due to: entity reference name can not contain character ' (position: TEXT seen ...<WKItemDescBaseLang>m&h ... @6:37)

XML:

<Header>
<ItemID>
<ID>SOFT-FAN-LTS-V3.00-AMADA</ID>
</ItemID>
<WKItemDescBaseLang>m&h MEASURING CYCLES "LASER TOOL MEASUREMENT"</WKItemDescBaseLang>
<BaseUOMCode>EA</BaseUOMCode>
<LotControlIndicator>1</LotControlIndicator>
</Header>

Apex:

Dom.Document doc = new Dom.Document();
doc.load( xml );

This error is due to & symbol in xml. But i'm uanble to fix this issue.
Thanks
Ravi
Pankaj_GanwaniPankaj_Ganwani
Hi,

Can you please try something like this?

String str = '<Header>
<ItemID>
<ID>SOFT-FAN-LTS-V3.00-AMADA</ID>
</ItemID>
<WKItemDescBaseLang>m&h MEASURING CYCLES "LASER TOOL MEASUREMENT"</WKItemDescBaseLang>
<BaseUOMCode>EA</BaseUOMCode>
<LotControlIndicator>1</LotControlIndicator>
</Header>';
str = str.replace('&','&amp;');
Dom.Document doc = new Dom.Document();
doc.load( str );