從SharePoint List SOAP請求返回某些字段時遇到一些麻煩。Jdom2 Sharepoint XML字段
這裏是XML:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:soap1="http://schemas.microsoft.com/sharepoint/soap/">
<soap:Header/>
<soap:Body>
<soap1:UpdateListItems>
<soap1:listName>69A3FFFA-782B-45D5-B776-2BE6D5645745</soap1:listName>
<soap1:updates>
<Batch OnError="Continue">
<Method ID="1" Cmd="New">
<Field Name="Title">New Item</Field>
</Method>
</Batch>
</soap1:updates>
</soap1:UpdateListItems>
</soap:Body>
</soap:Envelope>
我可以使用下面的代碼Jdom2抓住這樣的特定值:
// set your name spaces.
Namespace soap = Namespace.getNamespace("soap","http://www.w3.org/2003/05/soap-envelope");
Namespace soap1 = Namespace.getNamespace("soap1","http://schemas.microsoft.com/sharepoint/soap/");
// drill down into elements
Element rootNode = doc.getRootElement();
// Get Body node
Element body = rootNode.getChild("Body",soap);
// Get UpdateListItem Element
Element UpdateListItems = body.getChild("UpdateListItems",soap1);
// Get updates node
Element updates = UpdateListItems.getChild("updates",soap1);
// Set list name as String variable
String listNameString = UpdateListItems.getChild("listName",soap1).getText();
// Print list text value ** THIS WORKS**
System.out.println(listNameString);
不過,我似乎無法弄清楚如何選擇Field元素。 例如:我將如何選擇「標題」字段?
<Field Name="Title">New Item</Field>
UPDATE:
我也能夠從「現場」元素獲取屬性「名稱」,而只能返回或設置的屬性值的名稱。我需要能夠訪問「Field」元素中的測試。
我能得到這樣的屬性值: System.out.println(field.getAttribute("Name").getValue()); // Prints Title
,我可以得到的名字是這樣的: System.out.println(field.getAttribute("Name").getName()); // Prints Name
不過,我需要能夠返回的文本值元件。
更新2: 我沒有提到。 XML看起來是這樣的:
` <?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:soap1="http://schemas.microsoft.com/sharepoint/soap/">
<soap:Header/>
<soap:Body>
<soap1:UpdateListItems>
<soap1:listName>69A3FFFA-782B-45D5-B776-2BE6D5645745</soap1:listName>
<soap1:updates>
<Batch OnError="Continue">
<Method ID="1" Cmd="New">
<Field Name="Title">New Item</Field>
<Field Name="Classification" Type="Choice">Funny</Field>
<Field Name="Title">New Item</Field>
<Field Name="Title" Type="Text">Funny List Item</Field>
</Method>
</Batch>
</soap1:updates>
</soap1:UpdateListItems>
</soap:Body>
</soap:Envelope>`
我可以通過SoapUI提交這個到SharePoint,它的工作原理。但是如果有多個具有不同屬性的「字段」元素,我如何通過Jdom2選擇正確的元素?
我可以這樣做: String title = field.getText(); //returns New Item
但我將如何能夠抓住從使用「名稱」屬性其他「場」的元素的文本?
括號?什麼布爾克? – rolfl 2014-09-26 21:06:56
我需要能夠返回元素的文本值。 (New Item) '新項目 ' –
luskbo
2014-09-27 00:36:24