This post describes one of the limitation of Salesforce.com to handle XML data and the work around for it.
When using DOM.Document in Apex code. If we try to initialize XML data with data like:
we will be getting error message like:
System.XmlException:Failed to parse XML due to: unexpected character in markup 1 (position:START_TAG seen <1... @1:8)
This is because Salesforce.com doesn't support XML data where in tag names are numeric. So in order to parse such data we need methods that can replace such numeric values by strnig values.
One such method could be:
public String replaceNumerics(String rawXML)
{
for(integer i=0;i<150;i++) //pay attention while specifying the range. This could cause a governor limit Exception for Script statements
{
rawXML=rawXML.replace('<'+i+'>',' ');
rawXML=rawXML.replace('','');
}
return rawXML;
}
Now we can easily parse this XML.
No comments:
Post a Comment