Reputation: 2375
I'm reading a SharePoint list with java via a web service.
I've seen a number of examples that will read the list based on column titles you provide as an input.
Id like to know how to read all the items in a SharePoint list and get a list of all the column names (internal preferably).
Thanks for your thoughts guys
Upvotes: 0
Views: 1602
Reputation: 11
This will get the column internal names without decoding.
NamedNodeMap attributes = listResult.getElementsByTagName("z:row").item(0).getAttributes();
for (int i=0; i<attributa.getLength(); i++){
System.out.println("name: "+attributa.item(i).getNodeName());
}
However, it does not show the hidden columns. Any idea how?
Upvotes: 1
Reputation: 330
Maybe this link will help you:
http://blog.ashwani.co.in/blog/2013-07-28/connect-and-access-sharepoint-webservice-from-java/
see the displaySharePointList()
method he applies no query or queryOption and I think this will display all list items.
But if you want to get a list of the column names you have to create a CAML query (this is very vague answer but I don't know the perfect answer yet as I am looking into this by myself atm).
Edit: I found this great program helps you to create CAMLQueries:
https://spcamlqueryhelper.codeplex.com/
cheers
Upvotes: 1
Reputation: 257
GetListItemsResponse.GetListItemsResult result = listsoap.getListItems(listName, "", msQuery, viewFields, null, queryOptions, webID);
Object listResult = result.getContent().get(0);
if(listResult != null){
Element element = (Element)result.getContent().get(0);
NodeList nl = element.getElementsByTagName("z:row");
System.out.println("\n=> " + nl.getLength() + " results from SharePoint Online\n");
for(Integer i = 0; i < nl.getLength(); i++){
NamedNodeMap attributes = nl.item(i).getAttributes();
System.out.println(attributes.getNamedItem("ows_Title").getNodeValue());
}
This is the code currently being used. However I am having to specify the internal name explicitly in order to retrieve its data. Isn't there a way to retrieve all the internal names of the SharePointList via Java?
Upvotes: 0