2014-09-26 2 views
1

SharePoint 목록 SOAP 요청의 특정 필드를 반환하는 데 문제가 있습니다. 내가 방법을 알아낼 수없는 것, 그러나Jdom2 Sharepoint XML 필드

  // 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); 

: 나는 어떤 같은 값을 잡기 위해 다음 Jdom2 코드를 사용할 수 있어요

<?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> 

: 여기

은 XML이다 필드 요소를 선택하십시오. 예 : '제목'입력란은 어떻게 선택합니까?

<Field Name="Title">New Item</Field> 

UPDATE :

또한

나는 "필드"요소에서 속성 "이름"을 얻을 수 있지만 반환하거나 속성의 값의 이름을 설정할 수 있습니다. "필드"요소 내에서 테스트에 액세스 할 수 있어야합니다.

내가이 같은 속성의 값을 얻을 수 있습니다

:이 같은 이름을 얻을 수 있습니다 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에 제출할 수 있으며 작동합니다. 그러나 속성이 다른 "Field"요소가 여러 개있는 경우 Jdom2를 통해 올바른 필드를 선택하려면 어떻게해야합니까? String title = field.getText(); //returns New Item

을하지만 어떻게 "이름"속성을 사용하는 다른 "필드"요소의 텍스트를 잡을 수있을 것입니다 :

나는이 작업을 수행 할 수 있습니까?

+0

대괄호? 무슨 꼴인가? – rolfl

+0

요소의 텍스트 값을 반환 할 수 있어야합니다. ' 새 항목' – luskbo

답변

0

감사합니다. rolfl. 나는 그것을 알아. Child 요소를 반복하여 다른 "Field"특성에 액세스 할 수 있습니다. 그런 다음 속성 이름을 테스트하여 내용을 가져 오거나 설정합니다. 이것이 내가 생각할 수있는 최선의 방법입니다.

for (Element node : method.getChildren("Field")){ 
     if(node.getAttributeValue("Name").equalsIgnoreCase("Title")){ 
      node.setText("String"); 
     } 
     System.out.println(node.getAttribute("Name").getValue()); 
    } 
1

모두 네임 스페이스에 있습니다. 이 중 세 개가 soap, soap1이고 기본 네임 스페이스가 있습니다 (이 경우에는 ""). JDOM은이 네임 스페이스를 Namespace.NO_NAMESPACE로 지정합니다.

그래서, updates 요소에서 필드 요소를 얻으려면, 당신은 할 수 있습니다 : 당신이 원하는 경우

Element methods = updates.getChild("Method", Namespace.NO_NAMESPACE); 
Element field = methods.getChild("Field", Namespace.NO_NAMESPACE); 

다음은, 간단하게 할 수있는 공간 매개 변수에서이없는 getChild 방법을 사용하여 모두 같은 : 문서 3 네임 스페이스를 가지고 있으며, 필드 요소 (및 방법도)는 비누 또는 비누 1 네임 스페이스에없는 것을 것을

Element methods = updates.getChild("Method"); 
Element field = methods.getChild("Field"); 

여기에서 볼 수있는 중요한 일이다.

+0

맞지만 제목의 Name 속성에 대한 필드 요소의 값을 가져 오려고합니다. 당신의 대답을 읽기 바로 전에 당신을 답장 할 수있었습니다. 요소 field = method.getChild ("Field"); 그러나 Title 속성의 Field 요소에 액세스 할 수 있어야합니다. 지금까지는 다음과 같이 "Title"속성을 사용할 수 있습니다 : Attribute title = field.getAttribute ("Title"); 그러나 그것의 원본 가치를 얻는 것처럼 보일 수 없다. – luskbo

+0

나는 밀도가 있다고 생각한다. 나는 속성 값이나 텍스트 값 중 원하는 값을 알아낼 수 없다. 어느 쪽이든, 당신이'field'를 가지고 있다면, 당신은 속성이나 값을 얻을 수 있습니다 ...하지만, 이것은 말이되지 않습니다 : ""... Title의 Name 속성을위한 필드 요소의 값을 얻으려고 노력합니다. "* ... 그것은 합산하지 않습니다. – rolfl

+0

방금 ​​내 질문을 업데이트했습니다. 괄호 안의 값을 가져와야합니다. 그게 가능할 수있는 것보다 더 어렵게 만들 수 있습니다. 올린 사람 : ' 새 항목' 나는 "New Item"텍스트에 액세스해야합니다. – luskbo

관련 문제