. Advertisement .
..3..
. Advertisement .
..4..
I have the following java code, but I do not know how to find the correct result. Why has this problem occurred, and how can it be solved? Here is the code that I am running:
<?xml version="1.0" encoding="utf-8"?>
<ListDomainsResponse xmlns="http://sdb.amazonaws.com/doc/2009-04-15/">
<ListDomainsResult>
<DomainName>Audio</DomainName>
<DomainName>Course</DomainName>
<DomainName>DocumentContents</DomainName>
<DomainName>LectureSet</DomainName>
<DomainName>MetaData</DomainName>
<DomainName>Professors</DomainName>
<DomainName>Tag</DomainName>
</ListDomainsResult>
<ResponseMetadata>
<RequestId>42330b4a-e134-6aec-e62a-5869ac2b4575</RequestId>
<BoxUsage>0.0000071759</BoxUsage>
</ResponseMetadata>
</ListDomainsResponse>
XMLEventReader eventReader = xmlInputFactory.createXMLEventReader(response.getContent());
And this is the error text I receive:
com.amazonaws.http.HttpClient handleResponse: Unable to unmarshall response (ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.): <?xml version="1.0" encoding="utf-8"?>
<ListDomainsResponse xmlns="http://sdb.amazonaws.com/doc/2009-04-15/"><ListDomainsResult><DomainName>Audio</DomainName><DomainName>Course</DomainName><DomainName>DocumentContents</DomainName><DomainName>LectureSet</DomainName><DomainName>MetaData</DomainName><DomainName>Professors</DomainName><DomainName>Tag</DomainName></ListDomainsResult><ResponseMetadata><RequestId>42330b4a-e134-6aec-e62a-5869ac2b4575</RequestId><BoxUsage>0.0000071759</BoxUsage></ResponseMetadata></ListDomainsResponse>
javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(Unknown Source)
at com.sun.xml.internal.stream.XMLEventReaderImpl.nextEvent(Unknown Source)
at com.amazonaws.transform.StaxUnmarshallerContext.nextEvent(StaxUnmarshallerContext.java:153)
... (rest of lines omitted)
The cause: This error happens because your XML and XSD (or DTD) have different encodings:
XML file header:
XSD file header:
Another case can cause this is when anything appears before the XML document type declaration. In other words, you could have something like this in your buffer:
or even a special character such as a space.
The solution: The buffer may contain some special characters known as byte order markers. Do this before passing the buffer to the Parser…
While I was inspecting the xml file with notepad++, and then saving it, I encountered an issue. I did have the top utf-8
<?xml version="1.0" encoding="utf-8"?>
tag.Fixed by saving the file with Encoding(Tab), Encode in UTF-8,selected (was Encode In UTF-8-BOM).