我想從下面的字符串響應從Salesforce獲得標籤值,如何使用Java從SOAP響應中檢索元素值?
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/2006/04/metadata">
<soapenv:Body>
<listMetadataResponse>
<result>
<createdById>00528000001m5RRAAY</createdById>
<createdByName>Hariprasath Thanarajah</createdByName>
<createdDate>1970-01-01T00:00:00.000Z</createdDate>
<fileName>objects/EmailMessage.object</fileName>
<fullName>EmailMessage</fullName>
<id />
<lastModifiedById>00528000001m5RRAAY</lastModifiedById>
<lastModifiedByName>Hariprasath Thanarajah</lastModifiedByName>
<lastModifiedDate>1970-01-01T00:00:00.000Z</lastModifiedDate>
<namespacePrefix />
<type>CustomObject</type>
</result>
</listMetadataResponse>
</soapenv:Body>
</soapenv:Envelope>
上面我們有標籤<fullName>
。我需要獲取標籤內的值並將其放入String數組中。我已經嘗試過使用substring方法,但它只返回一個值。任何人都可以建議我這樣做嗎?
使用[XPath]中(http://docs.oracle.com/javase/8/docs/api/javax /xml/xpath/package-summary.html)或[創建DocumentBuilder](http://docs.oracle.com/javase/8/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#newDocumentBuilder-- ),將SOAP消息解析爲文檔,並使用[getElementsByTagName](http://docs.oracle.com/javase/8/docs/api/org/w3c/dom/Document.html#getElementsByTagName-java.lang。串-)。 – VGR
我試過這種方式。這個對我有用。 – Hariprasath