Reputation: 15
when i call mehtod getIdFromDatabase
for get id from my XML database but show me exception [Fatal Error] :1:1: Content is not allowed in prolog.
Call method getIdFromDatabase
:
nameLayer =getIdLayerFromDatabase("//Project/Layer[Name="+"'"+Name+"'"+"]/@idLayer","ProjectDataBase.xml");
Method in java:
public int getIdFromDatabase(String PathXPath, String Path) throws JAXBException {
int maxid = -1, id = -1;
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = domFactory.newDocumentBuilder();
//***** exception here******************************
Document dDoc = builder.parse(new InputSource(new ByteArrayInputStream(Path.getBytes("UTF-8"))));
XPath xPath = XPathFactory.newInstance().newXPath();
NodeList nl = (NodeList) xPath.evaluate(PathXPath, dDoc, XPathConstants.NODESET);
for (int i = 0; i < nl.getLength(); i++) {
id = Integer.parseInt(nl.item(i).getNodeValue());
}
} catch (Exception e) {
e.printStackTrace();
}
return id;
}
XML File:
<?xml version="1.0" encoding="UTF-8"?>
<Project xmlns="http://www.example.org/ProjectDataBase" name="شئؤ" location="Projects//شئؤ//ProjectDataBase.xml" CreationDate="2014-07-20">
<Layer idLayer="0">
<Name>طبقة 1</Name>
</Layer>
</Project>
Upvotes: 0
Views: 65
Reputation: 42030
The problem is that you're trying to parse the path and not the file. Change the line:
Document dDoc = builder.parse(new InputSource(new ByteArrayInputStream(Path.getBytes("UTF-8"))));
by:
Document dDoc = builder.parse(new FileInputStream(Path));
Upvotes: 1