From the last 2 days I am searching that how to parse XML with special chars like !@#$%^&*()\':;\", but I am not getting anything sufficient that how to implement it.. Can a
There is a free command line tool for transforming files with special characters in text to valid XML. It also assures that the file encoding matches what is specified in the declaration.
There is also a Java developer suite that allows you to use the parser to parse such files (called XPL) as an alternative to XML or a pre-process into XML. It uses a StAX-like process called StAX-PL.
You can try something like this, that is giving the reference for that special character.
Character Reference
& - &
< - <
> - >
" - "
' - '
UPDATE:
I had already answered in your question here so have a look at the Answer.
xml parsing with "&", "®", but still getting errors
These links might also help:
Parsing invalid ampersands with Android's XmlPullParsers
http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html
public void XmlParsing(String questions_xml)
{
try {
/** Handling XML */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
/** Create handler to handle XML Tags ( extends DefaultHandler ) */
MyXmlHandler myXMLHandler = new MyXmlHandler();
xr.setContentHandler(myXMLHandler);
xr.parse( new InputSource(new StringReader(questions_xml)));
} catch (Exception e) {
String err = (e.getMessage()==null)?"XMLParsing exception":e.getMessage();
Log.e("XMLParsing Exception",err);
}
}
now when I am trying to parse & then my app crashes?
documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
document = documentBuilder.parse(inputSource);
document.getDocumentElement().normalize();
The normalize method can handle special characters and entities for you.
public abstract void normalize ()
Added in API level 1
Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded, and is useful when operations (such as XPointer [XPointer] lookups) that depend on a particular document tree structure are to be used. If the parameter "normalize-characters" of the DOMConfiguration object attached to the Node.ownerDocument is true, this method will also fully normalize the characters of the Text nodes.
Note: In cases where the document contains CDATASections, the normalize operation alone may not be sufficient, since XPointers do not differentiate between Text nodes and CDATASection nodes.