special characters in xml stax parser file

vzlnutaa

New Member
\[code\]original xml file: <root> <article><artists><artist role="A&R Staff" artistId="1">Vance Anderson</artist><artists></article></root>\[/code\]When i read the file using stax parser and writing it to the new file it creates which makes the invalid xml file because there is no &amp in the new file.\[code\]generated xml file: <root><article> <artists><artist role='A&R Staff' artistId='1'>Vance Anderson</artist></article></root>\[/code\]few lines of code which i wrote :tagName = article\[code\] XMLEvent event = xmlEventReader.nextEvent(); if (event.isStartElement()) { StartElement startElement = event.asStartElement(); if (startElement.getName().getLocalPart().equalsIgnoreCase(tagName)) { Iterator<Attribute> attributes = startElement.getAttributes(); bStartRecord = Boolean.TRUE; } }if (bStartRecord) { String eventString = event.toString(); if (event.isCharacters()) { eventString = StringEscapeUtils.escapeXml(eventString); } stringbuilder.append(eventString + "\n"); }if (event.isEndElement()) { EndElement endElement = event.asEndElement(); if (endElement.getName().getLocalPart().equalsIgnoreCase(tagName)) {bStartRecord = Boolean.FALSE; closeFile(outputFile, stringbuilder); } //closeFile writes to the BufferedWriter \[/code\]
 
Back
Top