Hi, I'm trying to create a Web Service that validates an XML against an xsd file.
I've seen an example ( that uses javax.xml.validation against an org.w3c.dom.Document to validate.
The problem is that the Web Service receives the XML as a String, and I'm having errors when creating the Document.
This is what I have:
I get an error at line Document documentXML = parserXML.parse(isXML);
It gives
java.io.UTFDataFormatException: Invalid byte 2 of 2-byte UTF-8 sequence.
Any ideas why it is giving this error?
Thanks
I've seen an example ( that uses javax.xml.validation against an org.w3c.dom.Document to validate.
The problem is that the Web Service receives the XML as a String, and I'm having errors when creating the Document.
This is what I have:
Code:
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import javax.xml.parsers.*;
import org.w3c.dom.Document;
...
public String validateXML(String stringXML)
{
try
{
byte byteXML[] = stringXML.getBytes();
InputStream isXML = new ByteArrayInputStream(byteXML);
DocumentBuilder parserXML = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document documentXML = parserXML.parse(isXML);
...
}catch(Exception e){}
}
I get an error at line Document documentXML = parserXML.parse(isXML);
It gives
java.io.UTFDataFormatException: Invalid byte 2 of 2-byte UTF-8 sequence.
Any ideas why it is giving this error?
Thanks