0
現在、SOAP Webサービスの呼び出しを開発しています。XML文書の要素を動的に追加する必要があります。私はこのためにdom4jライブラリを使用しようとしますが、これは他のケースではうまくいきますが、現在のXMLドキュメントでは実現できません。dom4jでxml文書の要素を追加する
私の目標は、<urn:sObjects>
ノードの下に<fieldsToNull>fieldname</fieldsToNull>
の要素を追加することです。それはこのように言った非常に簡単そうですが、私は悲しげにここXML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com" xmlns:urn1="urn:sobject.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<urn:SessionHeader>
<urn:sessionId>sessionId</urn:sessionId>
</urn:SessionHeader><urn:AssignmentRuleHeader>
<urn:assignmentRuleId/><urn:useDefaultRule>1</urn:useDefaultRule></urn:AssignmentRuleHeader>
</soapenv:Header>
<soapenv:Body>
<urn:update>
<urn:sObjects>
<type>Account</type>
<Id/>
<Name/>
</urn:sObjects>
</urn:update>
</soapenv:Body>
私はいくつかのトピックで見つかった答えに応じて私の最後の試みでの作業に問題があると思います。それはerrosを生成しませんが、動作しません:
org.dom4j.Document msgDocument = ((routines.system.Document)input_row.Body).getDocument();
org.dom4j.Element root = msgDocument.getRootElement();
String xpathExpression = "Enveloppe.Body.update.Objects";
List<Node> nodes = root.selectNodes(xpathExpression);
for (Node node : nodes) {
Element e = (Element) node;
e.addElement("fieldsToNull").addText("Name");
}
routines.system.Document newMsgDocument = new routines.system.Document();
newMsgDocument.setDocument(msgDocument);
output_row.Body = newMsgDocument;
は、誰もがそれを行う方法についての私のヒントを与えることができましたか?
精度:私のコードはTalendジョブで設定されます。それは働くべき方法を変えず、ただそれを言います。