Having some trouble returning certain fields from a SharePoint List SOAP request.
Here is the 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>
I am able to use the following Jdom2 code to grab certain values like this:
// 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);
However, I can't seem to figure out how to select the Field elements. For example: How would I select the "Title" Field?
<Field Name="Title">New Item</Field>
UPDATE:
I also able to get the attribute "Name" from the "Field" element, but can only return or set the name of value of the attribute. I need to be able to access the test within the "Field" Element.
I can get the value of the attribute like this:
System.out.println(field.getAttribute("Name").getValue()); // Prints Title
And I can get the name like this:
System.out.println(field.getAttribute("Name").getName()); // Prints Name
But, I need to be able to return the text value of the element.
UPDATE 2: I didn't mention. The XML really looks like this:
` <?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>`
I can submit this via SoapUI to SharePoint and it works. But if there are multiple "Field" elements, with different attributes, how can I select the correct one via Jdom2?
I can do this:
String title = field.getText(); //returns New Item
But how would I be able to grab the text from other "Field" elements that use the "Name" attribute?