Reputation: 158
Can you please check what is wrong with this XML. Client is sending this XML request to process my application.
<soapenv:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:eze="http://ezeepay_test">
<soapenv:Header/>
<soapenv:Body>
<eze:RequestService
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<InputXml xsi:type="xsd:string">
<?xml version="1.0"
encoding="UTF-8"?>
<Request>
<BankID>05</BankID>
<TransactionID>1004114741235</TransactionID>
<TransactionType>Payment</TransactionType>
<ServiceType>Bill</ServiceType>
<TransactionDateStamp>04-04-2019 11:43:13</TransactionDateStamp>
<Amount>500</Amount>
<PaymentType>Cash</PaymentType>
</Request>
</InputXml>
</eze:RequestService>
</soapenv:Body>
</soapenv:Envelope>
I need to use xPath to iterate through the nodes to read the elements. But when I am parsing this XML I am getting the following Error.
I am prasing it using DocumentBuilderFactory.
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
//This is where I am getting Error.
Document doc = db.parse(new InputSource(new StringReader(XMLRequestString)));
Please let me know what manipulation I can do at my code Level.
Upvotes: 2
Views: 1614
Reputation: 163458
The answer to the question is that the data that has been sent is not compliant with the SOAP and XML standards and your server is quite right to reject it. The specific rule it is breaking is that the construct <?xml....?>
can only appear at the start of the document (it would be an XML declaration if it appeared at the start; it would be a processing instruction if it were not named "xml"; as it is, it is neither).
Don't be tempted to change your server code to accept any garbage the client sends you: that is the road to ruin.
Upvotes: 2