Tuesday, 8 July 2014

XML Exception while Parsing from String to DOM error



In my code, I am converting DOM object to String object and replace few strings and again writing to DOM object.


While doing so, am traversing many files, code works first time while for 2nd file, while writing to DOM object , java exception thrown.


I know root cause, as two root element for xml has getting generated , however don't have idea to eliminate



Java exception occurred:
org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.

at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)

at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)



@ Code
doc = docBuilder.parse(fXmlFile);
TramsformerObj.transform(DOMSource(doc),StreamResult(writerObj));

% Replace String
try
StrObj = writerObj.getBuffer.toString.replaceAll(Sourcestr,Replacestr);
catch ME
disp(ME.message)
end

% Convert String to DOM object
try
isObj.setCharacterStream(java.io.StringReader(StrObj));
docm = docBuilder.parse(isObj);
catch ME
disp(ME.message)
end


PS:- Note all object/ variables are available in memory and accesible. This code is of MATLAB, am invoking all packages of JAVA in MATLAB


No comments:

Post a Comment