Web Connection
Sharepoint API
Gravatar is a globally recognized avatar based on your email address. Sharepoint API
  George
  All
  Jun 21, 2019 @ 04:15pm

Hello all, I hope someone may be able to assist?

I have the following API call to our SharePoint server which returns the string (XML?) that is at the end of this post.

lcurl = "http://arsharepoint/ar/it/_api/search/query?querytext='srch'&rowlimit=1"

lcXML = loProxy.CallService(lcurl,loBody,"GET")

Eventually I need to be able to parse the XML into something like an object that I can use. I 'stole' the following code from Ricks documentation, but cannot get it to convert the XML into anything. If anyone knows what I am missing and can tell me I would be very grateful indeed.

Thanks.

loContainer = CREATEOBJECT("Empty")

ADDPROPERTY(loContainer,"objecttype","")

ADDPROPERTY(loContainer,"SPData",CREATEOBJECT("Collection"))

*** Now must add the blank Address object into collection

loAddress = CREATEOBJECT("Empty")

loContainer.spdata.Add(loAddress," ")

*** Now import into this object from our XML string

oXML = CREATEOBJECT("wwXML")`

oXML.lRecurseobjects = .T.

oXML.XmlToObject(lcXML,loContainer)`

<?xml version="1.0" encoding="utf-8"?>
<d:query xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" 
    xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" 
    xmlns:georss="http://www.georss.org/georss" 
    xmlns:gml="http://www.opengis.net/gml" m:type="Microsoft.Office.Server.Search.REST.SearchResult">
    <d:ElapsedTime m:type="Edm.Int32">187</d:ElapsedTime>
    <d:PrimaryQueryResult m:type="Microsoft.Office.Server.Search.REST.QueryResult">
        <d:CustomResults m:type="Collection(Microsoft.Office.Server.Search.REST.CustomResult)" />
        <d:QueryId>e2475370-6615-4820-b287-29aeb042138e</d:QueryId>
        <d:QueryRuleId m:type="Edm.Guid">00000000-0000-0000-0000-000000000000</d:QueryRuleId>
        <d:RefinementResults m:null="true" />
        <d:RelevantResults m:type="Microsoft.Office.Server.Search.REST.RelevantResults">
            <d:GroupTemplateId m:null="true" />
            <d:ItemTemplateId m:null="true" />
            <d:Properties>
                <d:element m:type="SP.KeyValue">
                    <d:Key>GenerationId</d:Key>
                    <d:Value>9223372036854775806</d:Value>
                    <d:ValueType>Edm.Int64</d:ValueType>
                </d:element>
                <d:element m:type="SP.KeyValue">
                    <d:Key>ExecutionTimeMs</d:Key>
                    <d:Value>0</d:Value>
                    <d:ValueType>Edm.Int32</d:ValueType>
                </d:element>
                <d:element m:type="SP.KeyValue">
                    <d:Key>QueryModification</d:Key>
                    <d:Value>srch -ContentClass=urn:content-class:SPSPeople</d:Value>
                    <d:ValueType>Edm.String</d:ValueType>
                </d:element>
                <d:element m:type="SP.KeyValue">
                    <d:Key>RenderTemplateId</d:Key>
                    <d:Value>~sitecollection/_catalogs/masterpage/Display Templates/Search/Group_Default.js</d:Value>
                    <d:ValueType>Edm.String</d:ValueType>
                </d:element>
                <d:element m:type="SP.KeyValue">
                    <d:Key>piPageImpressionBlockType</d:Key>
                    <d:Value>2</d:Value>
                    <d:ValueType>Edm.Byte</d:ValueType>
                </d:element>
                <d:element m:type="SP.KeyValue">
                    <d:Key>StartRecord</d:Key>
                    <d:Value>0</d:Value>
                    <d:ValueType>Edm.Int32</d:ValueType>
                </d:element>
                <d:element m:type="SP.KeyValue">
                    <d:Key>IsLastBlockInSubstrate</d:Key>
                    <d:Value>true</d:Value>
                    <d:ValueType>Edm.Boolean</d:ValueType>
                </d:element>
                <d:element m:type="SP.KeyValue">
                    <d:Key>IsFirstBlockInSubstrate</d:Key>
                    <d:Value>false</d:Value>
                    <d:ValueType>Edm.Boolean</d:ValueType>
                </d:element>
                <d:element m:type="SP.KeyValue">
                    <d:Key>IsFirstPinnedResultBlock</d:Key>
                    <d:Value>false</d:Value>
                    <d:ValueType>Edm.Boolean</d:ValueType>
                </d:element>
                <d:element m:type="SP.KeyValue">
                    <d:Key>IsLastPinnedResultBlock</d:Key>
                    <d:Value>false</d:Value>
                    <d:ValueType>Edm.Boolean</d:ValueType>
                </d:element>
                <d:element m:type="SP.KeyValue">
                    <d:Key>IsFirstRankedResultBlock</d:Key>
                    <d:Value>true</d:Value>
                    <d:ValueType>Edm.Boolean</d:ValueType>
                </d:element>
                <d:element m:type="SP.KeyValue">
                    <d:Key>IsLastRankedResultBlock</d:Key>
                    <d:Value>true</d:Value>
                    <d:ValueType>Edm.Boolean</d:ValueType>
                </d:element>
            </d:Properties>
            <d:ResultTitle m:null="true" />
            <d:ResultTitleUrl m:null="true" />
            <d:RowCount m:type="Edm.Int32">1</d:RowCount>
            <d:Table m:type="SP.SimpleDataTable">
                <d:Rows>
                    <d:element m:type="SP.SimpleDataRow">
                        <d:Cells>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>Rank</d:Key>
                                <d:Value>11.1311168670654</d:Value>
                                <d:ValueType>Edm.Double</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>DocId</d:Key>
                                <d:Value>1609371</d:Value>
                                <d:ValueType>Edm.Int64</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>WorkId</d:Key>
                                <d:Value>1609371</d:Value>
                                <d:ValueType>Edm.Int64</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>Title</d:Key>
                                <d:Value>TM.F7.01</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>Author</d:Key>
                                <d:Value>Yaskawa Electric America;Brett Peterson</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>Size</d:Key>
                                <d:Value>4415368</d:Value>
                                <d:ValueType>Edm.Int64</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>Path</d:Key>
                                <d:Value>http://arsharepoint/AR/Eng/Brett Peterson Active/AR_Converting/Shared Documents/E)Delta Modtech/Validation Package/3012 Docs/Maintenance Manual/09 Product Literature/Product Lit/Yaskawa/TM.F7.01.pdf</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>Description</d:Key>
                                <d:Value m:null="true" />
                                <d:ValueType>Null</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>Write</d:Key>
                                <d:Value>2007-09-14T15:45:39.0000000Z</d:Value>
                                <d:ValueType>Edm.DateTime</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>CollapsingStatus</d:Key>
                                <d:Value>0</d:Value>
                                <d:ValueType>Edm.Int64</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>HitHighlightedSummary</d:Key>
                                <d:Value xml:space="preserve">F7 Drive User Manual        Model: CIMR-F7U                     Document Number: TM.F7.01  i Warnings and Cautions This Section provides warnings and cautions pertinent to this <ddd/>
                                </d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>HitHighlightedProperties</d:Key>
                                <d:Value m:null="true" />
                                <d:ValueType>Null</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>contentclass</d:Key>
                                <d:Value>STS_ListItem_DocumentLibrary</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>PictureThumbnailURL</d:Key>
                                <d:Value m:null="true" />
                                <d:ValueType>Null</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>ServerRedirectedURL</d:Key>
                                <d:Value>http://arsharepoint/AR/Eng/Brett%20Peterson%20Active/AR_Converting/_layouts/15/WopiFrame.aspx?sourcedoc=/AR/Eng/Brett%20Peterson%20Active/AR_Converting/Shared%20Documents/E)Delta%20Modtech/Validation%20Package/3012%20Docs/Maintenance%20Manual/09%20Product%20Literature/Product%20Lit/Yaskawa/TM.F7.01.pdf&action=default&DefaultItemOpen=1</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>ServerRedirectedEmbedURL</d:Key>
                                <d:Value>http://arsharepoint/AR/Eng/Brett Peterson Active/AR_Converting/_layouts/15/WopiFrame.aspx?sourcedoc=%2FAR%2FEng%2FBrett%20Peterson%20Active%2FAR%5FConverting%2FShared%20Documents%2FE%29Delta%20Modtech%2FValidation%20Package%2F3012%20Docs%2FMaintenance%20Manual%2F09%20Product%20Literature%2FProduct%20Lit%2FYaskawa%2FTM%2EF7%2E01%2Epdf&action=interactivepreview</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>ServerRedirectedPreviewURL</d:Key>
                                <d:Value>http://arsharepoint/AR/Eng/Brett Peterson Active/AR_Converting/_layouts/15/WopiFrame.aspx?sourcedoc=%2FAR%2FEng%2FBrett%20Peterson%20Active%2FAR%5FConverting%2FShared%20Documents%2FE%29Delta%20Modtech%2FValidation%20Package%2F3012%20Docs%2FMaintenance%20Manual%2F09%20Product%20Literature%2FProduct%20Lit%2FYaskawa%2FTM%2EF7%2E01%2Epdf&action=imagepreview</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>FileExtension</d:Key>
                                <d:Value>pdf</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>ContentTypeId</d:Key>
                                <d:Value>0x0101007E612D5B95489144ABC16C224DDF17E7</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>ParentLink</d:Key>
                                <d:Value>http://arsharepoint/AR/Eng/Brett Peterson Active/AR_Converting/Shared Documents/E)Delta Modtech/Validation Package/3012 Docs/Maintenance Manual/09 Product Literature/Product Lit/Yaskawa</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>ViewsLifeTime</d:Key>
                                <d:Value m:null="true" />
                                <d:ValueType>Null</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>ViewsRecent</d:Key>
                                <d:Value m:null="true" />
                                <d:ValueType>Null</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>SectionNames</d:Key>
                                <d:Value></d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>SectionIndexes</d:Key>
                                <d:Value></d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>SiteLogo</d:Key>
                                <d:Value m:null="true" />
                                <d:ValueType>Null</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>SiteDescription</d:Key>
                                <d:Value m:null="true" />
                                <d:ValueType>Null</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>deeplinks</d:Key>
                                <d:Value m:null="true" />
                                <d:ValueType>Null</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>importance</d:Key>
                                <d:Value>0</d:Value>
                                <d:ValueType>Edm.Int64</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>SiteName</d:Key>
                                <d:Value>http://arsharepoint/AR/Eng</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>IsDocument</d:Key>
                                <d:Value>true</d:Value>
                                <d:ValueType>Edm.Boolean</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>LastModifiedTime</d:Key>
                                <d:Value>2007-09-14T15:45:39.0000000Z</d:Value>
                                <d:ValueType>Edm.DateTime</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>FileType</d:Key>
                                <d:Value>pdf</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>IsContainer</d:Key>
                                <d:Value>false</d:Value>
                                <d:ValueType>Edm.Boolean</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>WebTemplate</d:Key>
                                <d:Value m:null="true" />
                                <d:ValueType>Null</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>SecondaryFileExtension</d:Key>
                                <d:Value>pdf</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>docaclmeta</d:Key>
                                <d:Value m:null="true" />
                                <d:ValueType>Null</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>OriginalPath</d:Key>
                                <d:Value>http://arsharepoint/AR/Eng/Brett Peterson Active/AR_Converting/Shared Documents/E)Delta Modtech/Validation Package/3012 Docs/Maintenance Manual/09 Product Literature/Product Lit/Yaskawa/TM.F7.01.pdf</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>PartitionId</d:Key>
                                <d:Value>0c37852b-34d0-418e-91c6-2ac25af4be5b</d:Value>
                                <d:ValueType>Edm.Guid</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>UrlZone</d:Key>
                                <d:Value>0</d:Value>
                                <d:ValueType>Edm.Int32</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>AAMEnabledManagedProperties</d:Key>
                                <d:Value>AttachmentURI;deeplinks;DefaultEncodingURL;ExternalMediaURL;HierarchyUrl;OrgParentUrls;OrgUrls;OriginalPath;ParentLink;Path;PictureThumbnailURL;PictureURL;PublishingImage;recommendedfor;ServerRedirectedEmbedURL;ServerRedirectedPreviewURL;ServerRedirectedURL;SiteLogo;SitePath;SPSiteURL;UserEncodingURL</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>RenderTemplateId</d:Key>
                                <d:Value>~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default.js</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                            <d:element m:type="SP.KeyValue">
                                <d:Key>piSearchResultId</d:Key>
                                <d:Value>0_1</d:Value>
                                <d:ValueType>Edm.String</d:ValueType>
                            </d:element>
                        </d:Cells>
                    </d:element>
                </d:Rows>
            </d:Table>
            <d:TotalRows m:type="Edm.Int32">9</d:TotalRows>
            <d:TotalRowsIncludingDuplicates m:type="Edm.Int32">9</d:TotalRowsIncludingDuplicates>
        </d:RelevantResults>
        <d:SpecialTermResults m:null="true" />
    </d:PrimaryQueryResult>
    <d:Properties>
        <d:element m:type="SP.KeyValue">
            <d:Key>RowLimit</d:Key>
            <d:Value>1</d:Value>
            <d:ValueType>Edm.Int32</d:ValueType>
        </d:element>
        <d:element m:type="SP.KeyValue">
            <d:Key>SourceId</d:Key>
            <d:Value>8413cd39-2156-4e00-b54d-11efd9abdb89</d:Value>
            <d:ValueType>Edm.Guid</d:ValueType>
        </d:element>
        <d:element m:type="SP.KeyValue">
            <d:Key>WasGroupRestricted</d:Key>
            <d:Value>false</d:Value>
            <d:ValueType>Edm.Boolean</d:ValueType>
        </d:element>
        <d:element m:type="SP.KeyValue">
            <d:Key>IsPartial</d:Key>
            <d:Value>false</d:Value>
            <d:ValueType>Edm.Boolean</d:ValueType>
        </d:element>
        <d:element m:type="SP.KeyValue">
            <d:Key>EnableInterleaving</d:Key>
            <d:Value>true</d:Value>
            <d:ValueType>Edm.Boolean</d:ValueType>
        </d:element>
        <d:element m:type="SP.KeyValue">
            <d:Key>piPageImpression</d:Key>
            <d:Value>106254_1238_1033</d:Value>
            <d:ValueType>Edm.String</d:ValueType>
        </d:element>
        <d:element m:type="SP.KeyValue">
            <d:Key>SerializedQuery</d:Key>
            <d:Value>
                <Query Culture="en-US" EnableStemming="True" EnablePhonetic="False" EnableNicknames="False" IgnoreAllNoiseQuery="True" SummaryLength="180" MaxSnippetLength="180" DesiredSnippetLength="90" KeywordInclusion="0" QueryText="srch" QueryTemplate="" TrimDuplicates="True" Site="d5744e68-c068-4fe8-9db0-9198a9b6689b" Web="a9a8c2d3-aabd-4fe7-be66-44f7b42bfb70" KeywordType="True" HiddenConstraints="" />
            </d:Value>
            <d:ValueType>Edm.String</d:ValueType>
        </d:element>
    </d:Properties>
    <d:SecondaryQueryResults m:type="Collection(Microsoft.Office.Server.Search.REST.QueryResult)" />
    <d:SpellingSuggestion></d:SpellingSuggestion>
    <d:TriggeredRules m:type="Collection(Edm.Guid)" />
</d:query>
Gravatar is a globally recognized avatar based on your email address. re: Sharepoint API
  Rick Strahl
  George
  Jun 22, 2019 @ 11:43am

I'm sorry, but what are you doing here exactly?

The JsonServiceClient is meant to be used with JSON Services so it doesn't help you in any way for parsing the XML data.

The data that comes back are data sets when you probably have to parse individually. You can perhaps use FoxPro XML Adapter to read the individual data tables by pulling out just the individual tables and then reading the data, but more than likely you have to physically loop through the document with MSXML to read the data.

The tools Web Connection has won't help in a useful way with this XML parsing I think - you'll be better off just hand parsing.

You should also check and see if the service can return JSON data instead of XML. There are better tools available to parse JSON to FoxPro objects, than XML.

+++ Rick ---

© 1996-2019