org.xml.sax.SAXParseException: Reference is not allowed in prolog
I am trying to escape html characters of a string and use this string to build a DOM XML using parseXml method shown below. Next, I am trying to insert this DOM document into database. But, when I do that I am getting the following error:
org.xml.sax.SAXParseException: Reference is not allowed in prolog.
I have three questions:
1) I am not sure how to escape double quotes. I tried replaceAll(""", """) and am not sure if this is right.
2) Suppose I want a string starting and ending with double quotes (eg: "sony"), how do I code it? I tried something like:
String sony = ""sony""
Is this right? Will the above string contain "sony" along with double quotes or is there another way of doing it?
3)I am not sure what the "org.xml.sax.SAXParseException: Reference is not allowed in prolog." error means. Can someone help me fix this?
Thanks,
Sony
Steps in my code:
Utils. java
public static String escapeHtmlEntities(String s) {
return s.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll(""", """).
replaceAll(":", ":").replaceAll("/", "/");
}
public static Document parseXml (String xml) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(xml)));
doc.setXmlStandalone(false);
return doc;
}
TreeController.java
protected void notifyNewEntryCreated(String entryType) throws Exception {
for (Listener l : treeControlListeners)
l.newEntryCreated();
final DomNodeTreeModel domModel = (DomNodeTreeModel) getModel();
Element parent_item = getSelectedEntry();
String xml = Utils.escapeHtmlEntities("<entry xmlns=" + ""http://www.w3.org/2005/atom"" + "xmlns:libx=" +
""http://libx.org/xml/libx2">" + "<title>" + "New" + entryType + "</title>" +
"<updated>2010-71-22T11:08:43z</updated>" + "<author> <name>LibX Team</name>" +
"<uri>http://libx.org</uri>" + "<email>libx.org@gmail.com</email></author>" +
"<libx:" + entryType + "></libx:" + entryType + ">" + "</entry>");
xmlModel.insertNewEntry(xml, getSelectedId());
}
XMLDataModel.java
public void insertNewEntry (String xml, String parent_id) throws Exception {
insertNewEntry(Utils.parseXml(xml).getDocumentElement(), parent_id);
}
public void insertNewEntry (Element elem, String parent_id) throws Exception {
// inserting an entry with no libx: tag will create a storage leak
if (elem.getElementsByTagName("libx:package").getLength() +
elem.getElementsByTagName("libx:libapp").getLength() +
elem.getElementsByTagName("libx:module").getLength() < 1) {
// TODO: throw exception here instead of return
return;
}
XQPreparedExpression xqp = Q.get("insert_new_entry.xq");
xqp.bindNode(new QName("entry"), elem.getOwnerDocument(), null);
xqp.bindString(new QName("parent_id"), parent_id, null);
xqp.executeQuery();
xqp.close();
updateRoots();
}
- insert_new_entry.xq
declare namespace libx='http://libx.org/xml/libx2';
declare namespace atom='http://www.w3.org/2005/atom';
declare variable $entry as xs:anyAtomicType external;
declare variable $parent_id as xs:string external;
declare variable $feed as xs:anyAtomicType := doc('libx2_feed')/atom:feed;
declare variable $metadata as xs:anyAtomicType := doc('libx2_meta')/metadata;
let $curid := $metadata/curid
return replace value of node $curid with data($curid) + 1,
let $newid := data($metadata/curid) + 1
return insert node
{$newid}{
$entry//
}
into $feed,
let $newid := data($metadata/curid) + 1
return if ($parent_id = 'root') then ()
else
insert node http://libx.org/xml/libx2' /> into
$feed/atom:entry[atom:id=$parent_id]//(libx:module|libx:libapp|libx:package)
java html dom xquery xml-parsing
add a comment |
I am trying to escape html characters of a string and use this string to build a DOM XML using parseXml method shown below. Next, I am trying to insert this DOM document into database. But, when I do that I am getting the following error:
org.xml.sax.SAXParseException: Reference is not allowed in prolog.
I have three questions:
1) I am not sure how to escape double quotes. I tried replaceAll(""", """) and am not sure if this is right.
2) Suppose I want a string starting and ending with double quotes (eg: "sony"), how do I code it? I tried something like:
String sony = ""sony""
Is this right? Will the above string contain "sony" along with double quotes or is there another way of doing it?
3)I am not sure what the "org.xml.sax.SAXParseException: Reference is not allowed in prolog." error means. Can someone help me fix this?
Thanks,
Sony
Steps in my code:
Utils. java
public static String escapeHtmlEntities(String s) {
return s.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll(""", """).
replaceAll(":", ":").replaceAll("/", "/");
}
public static Document parseXml (String xml) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(xml)));
doc.setXmlStandalone(false);
return doc;
}
TreeController.java
protected void notifyNewEntryCreated(String entryType) throws Exception {
for (Listener l : treeControlListeners)
l.newEntryCreated();
final DomNodeTreeModel domModel = (DomNodeTreeModel) getModel();
Element parent_item = getSelectedEntry();
String xml = Utils.escapeHtmlEntities("<entry xmlns=" + ""http://www.w3.org/2005/atom"" + "xmlns:libx=" +
""http://libx.org/xml/libx2">" + "<title>" + "New" + entryType + "</title>" +
"<updated>2010-71-22T11:08:43z</updated>" + "<author> <name>LibX Team</name>" +
"<uri>http://libx.org</uri>" + "<email>libx.org@gmail.com</email></author>" +
"<libx:" + entryType + "></libx:" + entryType + ">" + "</entry>");
xmlModel.insertNewEntry(xml, getSelectedId());
}
XMLDataModel.java
public void insertNewEntry (String xml, String parent_id) throws Exception {
insertNewEntry(Utils.parseXml(xml).getDocumentElement(), parent_id);
}
public void insertNewEntry (Element elem, String parent_id) throws Exception {
// inserting an entry with no libx: tag will create a storage leak
if (elem.getElementsByTagName("libx:package").getLength() +
elem.getElementsByTagName("libx:libapp").getLength() +
elem.getElementsByTagName("libx:module").getLength() < 1) {
// TODO: throw exception here instead of return
return;
}
XQPreparedExpression xqp = Q.get("insert_new_entry.xq");
xqp.bindNode(new QName("entry"), elem.getOwnerDocument(), null);
xqp.bindString(new QName("parent_id"), parent_id, null);
xqp.executeQuery();
xqp.close();
updateRoots();
}
- insert_new_entry.xq
declare namespace libx='http://libx.org/xml/libx2';
declare namespace atom='http://www.w3.org/2005/atom';
declare variable $entry as xs:anyAtomicType external;
declare variable $parent_id as xs:string external;
declare variable $feed as xs:anyAtomicType := doc('libx2_feed')/atom:feed;
declare variable $metadata as xs:anyAtomicType := doc('libx2_meta')/metadata;
let $curid := $metadata/curid
return replace value of node $curid with data($curid) + 1,
let $newid := data($metadata/curid) + 1
return insert node
{$newid}{
$entry//
}
into $feed,
let $newid := data($metadata/curid) + 1
return if ($parent_id = 'root') then ()
else
insert node http://libx.org/xml/libx2' /> into
$feed/atom:entry[atom:id=$parent_id]//(libx:module|libx:libapp|libx:package)
java html dom xquery xml-parsing
Hi, I learnt that the error: "org.xml.sax.SAXParseException: Reference is not allowed in prolog." is thrown when XML being loaded doesn't have valid XML. So, the whole issue boils down to converting the string into a valid xml. So I suppose the whole issue boils down to converting the string "xml" used in above example into a valid xml. I am guessing something is wrong with the way am escaping and using html double quote characters. I am still confused with questions 1 and 2 in the above post. Thanks for the help. -Sony
– sony
Jul 22 '10 at 18:45
add a comment |
I am trying to escape html characters of a string and use this string to build a DOM XML using parseXml method shown below. Next, I am trying to insert this DOM document into database. But, when I do that I am getting the following error:
org.xml.sax.SAXParseException: Reference is not allowed in prolog.
I have three questions:
1) I am not sure how to escape double quotes. I tried replaceAll(""", """) and am not sure if this is right.
2) Suppose I want a string starting and ending with double quotes (eg: "sony"), how do I code it? I tried something like:
String sony = ""sony""
Is this right? Will the above string contain "sony" along with double quotes or is there another way of doing it?
3)I am not sure what the "org.xml.sax.SAXParseException: Reference is not allowed in prolog." error means. Can someone help me fix this?
Thanks,
Sony
Steps in my code:
Utils. java
public static String escapeHtmlEntities(String s) {
return s.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll(""", """).
replaceAll(":", ":").replaceAll("/", "/");
}
public static Document parseXml (String xml) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(xml)));
doc.setXmlStandalone(false);
return doc;
}
TreeController.java
protected void notifyNewEntryCreated(String entryType) throws Exception {
for (Listener l : treeControlListeners)
l.newEntryCreated();
final DomNodeTreeModel domModel = (DomNodeTreeModel) getModel();
Element parent_item = getSelectedEntry();
String xml = Utils.escapeHtmlEntities("<entry xmlns=" + ""http://www.w3.org/2005/atom"" + "xmlns:libx=" +
""http://libx.org/xml/libx2">" + "<title>" + "New" + entryType + "</title>" +
"<updated>2010-71-22T11:08:43z</updated>" + "<author> <name>LibX Team</name>" +
"<uri>http://libx.org</uri>" + "<email>libx.org@gmail.com</email></author>" +
"<libx:" + entryType + "></libx:" + entryType + ">" + "</entry>");
xmlModel.insertNewEntry(xml, getSelectedId());
}
XMLDataModel.java
public void insertNewEntry (String xml, String parent_id) throws Exception {
insertNewEntry(Utils.parseXml(xml).getDocumentElement(), parent_id);
}
public void insertNewEntry (Element elem, String parent_id) throws Exception {
// inserting an entry with no libx: tag will create a storage leak
if (elem.getElementsByTagName("libx:package").getLength() +
elem.getElementsByTagName("libx:libapp").getLength() +
elem.getElementsByTagName("libx:module").getLength() < 1) {
// TODO: throw exception here instead of return
return;
}
XQPreparedExpression xqp = Q.get("insert_new_entry.xq");
xqp.bindNode(new QName("entry"), elem.getOwnerDocument(), null);
xqp.bindString(new QName("parent_id"), parent_id, null);
xqp.executeQuery();
xqp.close();
updateRoots();
}
- insert_new_entry.xq
declare namespace libx='http://libx.org/xml/libx2';
declare namespace atom='http://www.w3.org/2005/atom';
declare variable $entry as xs:anyAtomicType external;
declare variable $parent_id as xs:string external;
declare variable $feed as xs:anyAtomicType := doc('libx2_feed')/atom:feed;
declare variable $metadata as xs:anyAtomicType := doc('libx2_meta')/metadata;
let $curid := $metadata/curid
return replace value of node $curid with data($curid) + 1,
let $newid := data($metadata/curid) + 1
return insert node
{$newid}{
$entry//
}
into $feed,
let $newid := data($metadata/curid) + 1
return if ($parent_id = 'root') then ()
else
insert node http://libx.org/xml/libx2' /> into
$feed/atom:entry[atom:id=$parent_id]//(libx:module|libx:libapp|libx:package)
java html dom xquery xml-parsing
I am trying to escape html characters of a string and use this string to build a DOM XML using parseXml method shown below. Next, I am trying to insert this DOM document into database. But, when I do that I am getting the following error:
org.xml.sax.SAXParseException: Reference is not allowed in prolog.
I have three questions:
1) I am not sure how to escape double quotes. I tried replaceAll(""", """) and am not sure if this is right.
2) Suppose I want a string starting and ending with double quotes (eg: "sony"), how do I code it? I tried something like:
String sony = ""sony""
Is this right? Will the above string contain "sony" along with double quotes or is there another way of doing it?
3)I am not sure what the "org.xml.sax.SAXParseException: Reference is not allowed in prolog." error means. Can someone help me fix this?
Thanks,
Sony
Steps in my code:
Utils. java
public static String escapeHtmlEntities(String s) {
return s.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll(""", """).
replaceAll(":", ":").replaceAll("/", "/");
}
public static Document parseXml (String xml) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(xml)));
doc.setXmlStandalone(false);
return doc;
}
TreeController.java
protected void notifyNewEntryCreated(String entryType) throws Exception {
for (Listener l : treeControlListeners)
l.newEntryCreated();
final DomNodeTreeModel domModel = (DomNodeTreeModel) getModel();
Element parent_item = getSelectedEntry();
String xml = Utils.escapeHtmlEntities("<entry xmlns=" + ""http://www.w3.org/2005/atom"" + "xmlns:libx=" +
""http://libx.org/xml/libx2">" + "<title>" + "New" + entryType + "</title>" +
"<updated>2010-71-22T11:08:43z</updated>" + "<author> <name>LibX Team</name>" +
"<uri>http://libx.org</uri>" + "<email>libx.org@gmail.com</email></author>" +
"<libx:" + entryType + "></libx:" + entryType + ">" + "</entry>");
xmlModel.insertNewEntry(xml, getSelectedId());
}
XMLDataModel.java
public void insertNewEntry (String xml, String parent_id) throws Exception {
insertNewEntry(Utils.parseXml(xml).getDocumentElement(), parent_id);
}
public void insertNewEntry (Element elem, String parent_id) throws Exception {
// inserting an entry with no libx: tag will create a storage leak
if (elem.getElementsByTagName("libx:package").getLength() +
elem.getElementsByTagName("libx:libapp").getLength() +
elem.getElementsByTagName("libx:module").getLength() < 1) {
// TODO: throw exception here instead of return
return;
}
XQPreparedExpression xqp = Q.get("insert_new_entry.xq");
xqp.bindNode(new QName("entry"), elem.getOwnerDocument(), null);
xqp.bindString(new QName("parent_id"), parent_id, null);
xqp.executeQuery();
xqp.close();
updateRoots();
}
- insert_new_entry.xq
declare namespace libx='http://libx.org/xml/libx2';
declare namespace atom='http://www.w3.org/2005/atom';
declare variable $entry as xs:anyAtomicType external;
declare variable $parent_id as xs:string external;
declare variable $feed as xs:anyAtomicType := doc('libx2_feed')/atom:feed;
declare variable $metadata as xs:anyAtomicType := doc('libx2_meta')/metadata;
let $curid := $metadata/curid
return replace value of node $curid with data($curid) + 1,
let $newid := data($metadata/curid) + 1
return insert node
{$newid}{
$entry//
}
into $feed,
let $newid := data($metadata/curid) + 1
return if ($parent_id = 'root') then ()
else
insert node http://libx.org/xml/libx2' /> into
$feed/atom:entry[atom:id=$parent_id]//(libx:module|libx:libapp|libx:package)
java html dom xquery xml-parsing
java html dom xquery xml-parsing
edited Jul 23 '10 at 0:42
mdma
48k1078112
48k1078112
asked Jul 22 '10 at 17:49
sonysony
70962648
70962648
Hi, I learnt that the error: "org.xml.sax.SAXParseException: Reference is not allowed in prolog." is thrown when XML being loaded doesn't have valid XML. So, the whole issue boils down to converting the string into a valid xml. So I suppose the whole issue boils down to converting the string "xml" used in above example into a valid xml. I am guessing something is wrong with the way am escaping and using html double quote characters. I am still confused with questions 1 and 2 in the above post. Thanks for the help. -Sony
– sony
Jul 22 '10 at 18:45
add a comment |
Hi, I learnt that the error: "org.xml.sax.SAXParseException: Reference is not allowed in prolog." is thrown when XML being loaded doesn't have valid XML. So, the whole issue boils down to converting the string into a valid xml. So I suppose the whole issue boils down to converting the string "xml" used in above example into a valid xml. I am guessing something is wrong with the way am escaping and using html double quote characters. I am still confused with questions 1 and 2 in the above post. Thanks for the help. -Sony
– sony
Jul 22 '10 at 18:45
Hi, I learnt that the error: "org.xml.sax.SAXParseException: Reference is not allowed in prolog." is thrown when XML being loaded doesn't have valid XML. So, the whole issue boils down to converting the string into a valid xml. So I suppose the whole issue boils down to converting the string "xml" used in above example into a valid xml. I am guessing something is wrong with the way am escaping and using html double quote characters. I am still confused with questions 1 and 2 in the above post. Thanks for the help. -Sony
– sony
Jul 22 '10 at 18:45
Hi, I learnt that the error: "org.xml.sax.SAXParseException: Reference is not allowed in prolog." is thrown when XML being loaded doesn't have valid XML. So, the whole issue boils down to converting the string into a valid xml. So I suppose the whole issue boils down to converting the string "xml" used in above example into a valid xml. I am guessing something is wrong with the way am escaping and using html double quote characters. I am still confused with questions 1 and 2 in the above post. Thanks for the help. -Sony
– sony
Jul 22 '10 at 18:45
add a comment |
2 Answers
2
active
oldest
votes
You can check out Tidy specification. its a spec released by w3c. Almost all recent languages have their own implementation.
rather than just replace or care only to < ,>, & just configure JTidy ( for java ) options and parse. this abstracts all the complication of Xml escape thing.
i have used both python , java and marklogic based tidy implementations. all solved my purposes
add a comment |
To escape a double quote, use the "
entity, which is predefined in XML.
So, your example string, say an attribute value, will look like
<person name=""sony""/>
There is also '
for apostrophe/single quote.
I see you have lots of replaceAll calls, but the replacements seem to be the same? There are some other characters that cannot be used literally, but should be escaped:
& --> &
> --> >
< --> <
" --> "
' --> '
(EDIT: ok, I see this is just formatting - the entities are being turned into they're actual values when being presented by SO.)
The SAX exception is the parser grumbling because of the invalid XML.
As well as escaping the text, you will need to ensure it adheres to the well-formedness rules of XML. There's quite a bit to get right, so it's often simpler to use a 3rd party library to write out the XML. For example, the XMLWriter in dom4j.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3311781%2forg-xml-sax-saxparseexception-reference-is-not-allowed-in-prolog%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can check out Tidy specification. its a spec released by w3c. Almost all recent languages have their own implementation.
rather than just replace or care only to < ,>, & just configure JTidy ( for java ) options and parse. this abstracts all the complication of Xml escape thing.
i have used both python , java and marklogic based tidy implementations. all solved my purposes
add a comment |
You can check out Tidy specification. its a spec released by w3c. Almost all recent languages have their own implementation.
rather than just replace or care only to < ,>, & just configure JTidy ( for java ) options and parse. this abstracts all the complication of Xml escape thing.
i have used both python , java and marklogic based tidy implementations. all solved my purposes
add a comment |
You can check out Tidy specification. its a spec released by w3c. Almost all recent languages have their own implementation.
rather than just replace or care only to < ,>, & just configure JTidy ( for java ) options and parse. this abstracts all the complication of Xml escape thing.
i have used both python , java and marklogic based tidy implementations. all solved my purposes
You can check out Tidy specification. its a spec released by w3c. Almost all recent languages have their own implementation.
rather than just replace or care only to < ,>, & just configure JTidy ( for java ) options and parse. this abstracts all the complication of Xml escape thing.
i have used both python , java and marklogic based tidy implementations. all solved my purposes
answered Jul 29 '10 at 23:49
kadalamittaikadalamittai
1,41811116
1,41811116
add a comment |
add a comment |
To escape a double quote, use the "
entity, which is predefined in XML.
So, your example string, say an attribute value, will look like
<person name=""sony""/>
There is also '
for apostrophe/single quote.
I see you have lots of replaceAll calls, but the replacements seem to be the same? There are some other characters that cannot be used literally, but should be escaped:
& --> &
> --> >
< --> <
" --> "
' --> '
(EDIT: ok, I see this is just formatting - the entities are being turned into they're actual values when being presented by SO.)
The SAX exception is the parser grumbling because of the invalid XML.
As well as escaping the text, you will need to ensure it adheres to the well-formedness rules of XML. There's quite a bit to get right, so it's often simpler to use a 3rd party library to write out the XML. For example, the XMLWriter in dom4j.
add a comment |
To escape a double quote, use the "
entity, which is predefined in XML.
So, your example string, say an attribute value, will look like
<person name=""sony""/>
There is also '
for apostrophe/single quote.
I see you have lots of replaceAll calls, but the replacements seem to be the same? There are some other characters that cannot be used literally, but should be escaped:
& --> &
> --> >
< --> <
" --> "
' --> '
(EDIT: ok, I see this is just formatting - the entities are being turned into they're actual values when being presented by SO.)
The SAX exception is the parser grumbling because of the invalid XML.
As well as escaping the text, you will need to ensure it adheres to the well-formedness rules of XML. There's quite a bit to get right, so it's often simpler to use a 3rd party library to write out the XML. For example, the XMLWriter in dom4j.
add a comment |
To escape a double quote, use the "
entity, which is predefined in XML.
So, your example string, say an attribute value, will look like
<person name=""sony""/>
There is also '
for apostrophe/single quote.
I see you have lots of replaceAll calls, but the replacements seem to be the same? There are some other characters that cannot be used literally, but should be escaped:
& --> &
> --> >
< --> <
" --> "
' --> '
(EDIT: ok, I see this is just formatting - the entities are being turned into they're actual values when being presented by SO.)
The SAX exception is the parser grumbling because of the invalid XML.
As well as escaping the text, you will need to ensure it adheres to the well-formedness rules of XML. There's quite a bit to get right, so it's often simpler to use a 3rd party library to write out the XML. For example, the XMLWriter in dom4j.
To escape a double quote, use the "
entity, which is predefined in XML.
So, your example string, say an attribute value, will look like
<person name=""sony""/>
There is also '
for apostrophe/single quote.
I see you have lots of replaceAll calls, but the replacements seem to be the same? There are some other characters that cannot be used literally, but should be escaped:
& --> &
> --> >
< --> <
" --> "
' --> '
(EDIT: ok, I see this is just formatting - the entities are being turned into they're actual values when being presented by SO.)
The SAX exception is the parser grumbling because of the invalid XML.
As well as escaping the text, you will need to ensure it adheres to the well-formedness rules of XML. There's quite a bit to get right, so it's often simpler to use a 3rd party library to write out the XML. For example, the XMLWriter in dom4j.
edited May 29 '13 at 22:20
Daniel Haley
38.6k45280
38.6k45280
answered Jul 23 '10 at 0:41
mdmamdma
48k1078112
48k1078112
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3311781%2forg-xml-sax-saxparseexception-reference-is-not-allowed-in-prolog%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hi, I learnt that the error: "org.xml.sax.SAXParseException: Reference is not allowed in prolog." is thrown when XML being loaded doesn't have valid XML. So, the whole issue boils down to converting the string into a valid xml. So I suppose the whole issue boils down to converting the string "xml" used in above example into a valid xml. I am guessing something is wrong with the way am escaping and using html double quote characters. I am still confused with questions 1 and 2 in the above post. Thanks for the help. -Sony
– sony
Jul 22 '10 at 18:45