locked
How to fetch top 50 records in XML RRS feed

  • Question

  • User-1313990200 posted

    This is my xml returning from a WCF service

    <server>
    <responses>
    <Session.loginRs status="success" sessionID="A3786008:DB8D4E58:96A1B82A:E606D2BC:7A35D91D:48E90C41" expiredPassword="0" fullName="Express Admin" roleBasedSecurity="1" entityID="1" userID="1" partyID="0" consumerID="0" />
    <IntegrationCBO.ProcessWCFServiceRs status="success">
    <Payload xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <request xmlns="http://abr.business.gov.au/ABRXMLSearch/">
    <nameSearchRequest>
    <authenticationGUID>88bf33e2-96a6-402c-a870-47c03af2a80b</authenticationGUID>
    <name>ANZ</name>
    <filters>
    <nameType>
    <tradingName>Y</tradingName>
    <legalName>Y</legalName>
    </nameType>
    <postcode xsi:nil="true" />
    <stateCode>
    <QLD>Y</QLD>
    <NT>Y</NT>
    <SA>Y</SA>
    <WA>Y</WA>
    <VIC>Y</VIC>
    <ACT>Y</ACT>
    <TAS>Y</TAS>
    <NSW>Y</NSW>
    </stateCode>
    </filters>
    </nameSearchRequest>
    </request>
    <response xmlns="http://abr.business.gov.au/ABRXMLSearch/">
    <usageStatement>The Registrar of the ABR monitors the quality of the information available on this website and updates the information regularly. However, neither the Registrar of the ABR nor the Commonwealth guarantee that the information available through this service (including search results) is accurate, up to date, complete or accept any liability arising from the use of or reliance upon this site.</usageStatement>
    <dateRegisterLastUpdated>2019-10-22</dateRegisterLastUpdated>
    <dateTimeRetrieved>2019-10-22T14:03:33.3141574+05:30</dateTimeRetrieved>
    <searchResultsList>
    <numberOfRecords>201</numberOfRecords>
    <exceedsMaximum>N</exceedsMaximum>
    <searchResultsRecord>
    <ABN>
    <identifierValue>11005357522</identifierValue>
    <identifierStatus>Active</identifierStatus>
    </ABN>
    <businessName>
    <organisationName>ANZ</organisationName>
    <score>100</score>
    <isCurrentIndicator>Y</isCurrentIndicator>
    </businessName>
    <mainBusinessPhysicalAddress>
    <stateCode>VIC</stateCode>
    <postcode>3008</postcode>
    <isCurrentIndicator>Y</isCurrentIndicator>
    </mainBusinessPhysicalAddress>
    </searchResultsRecord>
    <searchResultsRecord>
    <ABN>
    <identifierValue>30146899103</identifierValue>
    <identifierStatus>Cancelled</identifierStatus>
    </ABN>
    <mainName>
    <organisationName>ANZ COMPANIES PTY LIMITED</organisationName>
    <score>100</score>
    <isCurrentIndicator>Y</isCurrentIndicator>
    </mainName>
    <mainBusinessPhysicalAddress>
    <stateCode>NSW</stateCode>
    <postcode>2134</postcode>
    <isCurrentIndicator>Y</isCurrentIndicator>
    </mainBusinessPhysicalAddress>
    </searchResultsRecord>
    <searchResultsRecord>
    <ABN>
    <identifierValue>22169448220</identifierValue>
    <identifierStatus>Active</identifierStatus>
    </ABN>
    <mainName>
    <organisationName>ANZ CORPORATION PTY LTD</organisationName>
    <score>100</score>
    <isCurrentIndicator>Y</isCurrentIndicator>
    </mainName>
    <mainBusinessPhysicalAddress>
    <stateCode>NSW</stateCode>
    <postcode>2009</postcode>
    <isCurrentIndicator>Y</isCurrentIndicator>
    </mainBusinessPhysicalAddress>
    </searchResultsRecord>

    I need to fetch searchResultsRecord node for 50 times

    Wednesday, October 23, 2019 3:47 AM

All replies

  • User288213138 posted

    Hi Chandu123,

    How to fetch top 50 records in XML

    I need to fetch searchResultsRecord node for 50 times

    You title says want to fetch top50 records in XML. but you also say want to fetch searchResultsRecord node for 50 times.

    What's your question?

    If you want to fetch top50 records in XML, you can try below code.

    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    
    
    protected void Button1_Click(object sender, EventArgs e)
            {
                XDocument xmlDocument = XDocument.Load(@"C:\Users\samwu\Desktop\Test.xml");
                var test = xmlDocument.Descendants("searchResultsRecord ").Take(50);                     
            }

    Best regards,

    Sam

    Wednesday, October 23, 2019 6:49 AM
  • User-1313990200 posted

    I need to fetch searchResultsRecord node for 50 times.

    Wednesday, October 23, 2019 7:10 AM
  • User288213138 posted

    Hi chandu123,

    I need to fetch searchResultsRecord node for 50 times.

    I found that the top 50 searchResultsRecord is not 50 times?

    please post more details information about your requirement.

    Best regards,

    Sam

    Wednesday, October 23, 2019 8:15 AM
  • User-1313990200 posted

    My xml Consists of 200 rows but i cant paste them here so for example i have posted a few. I have that structure from them i have to filter or show 50 records.

    Wednesday, October 23, 2019 8:50 AM
  • User288213138 posted

    Hi chandu123,

    XDocument xmlDocument = XDocument.Load(@"C:\Users\samwu\Desktop\Test.xml");
    var test = xmlDocument.Descendants("searchResultsRecord ").Take(50); 

    Is this method unable to get the 50 searchResultsRecord in your xml?

    Can you show me your code?

    Best regards,

    Sam

    Wednesday, October 23, 2019 10:23 AM
  • User-1313990200 posted

    This is not working as the Xpath is wrong.

    Wednesday, October 23, 2019 1:50 PM
  • User288213138 posted

    Hi chandu123,

    This is not working as the Xpath is wrong

    Please show me what's wrong with Xpath?

    and please show me your code.

    Best regards,

    Sam

    Thursday, October 24, 2019 1:45 AM
  • User-1313990200 posted

    XmlNodeList nodesInfo = responseXml.SelectNodes("./searchResultsList/searchResultsRecord");


    foreach (XmlNode result in responseXml.SelectNodes("Payload"))
    {
    XmlDocument doc1 = new XmlDocument();
    result.AppendChild(doc1);
    }

    I want to find the searchResultsRecord node and loop through the records and i want to write them to a new file.

    Thursday, October 24, 2019 3:31 AM
  • User288213138 posted

    Hi chandu123,

    I want to find the searchResultsRecord node

    XmlNodeList nodesInfo = responseXml.SelectNodes("./searchResultsList/searchResultsRecord");

    This code has Fetch all the searchResultsRecord nodes in you xml.

    loop through the records

    what records do you want to traverse?

    foreach (XmlNode result in responseXml.SelectNodes("Payload"))

    use this code can loop through the code.

    i want to write them to a new file.

    You can try below code:

    string s = "<xml><foo></foo></xml>";
                XmlDocument xdoc = new XmlDocument();
                xdoc.LoadXml(s);
                xdoc.Save("your path");

    Best regards,

    Sam

    Thursday, October 24, 2019 9:59 AM
  • User-1313990200 posted

    I have to traverse through searchResultsRecord records and display them or write to another xml. I have tried your code already.

    Friday, October 25, 2019 6:06 AM
  • User288213138 posted

    Hi chandu123,

    I have tried your code already

    Can you tell me what is wrong with my code? What error have you encountered?

    I have to traverse through searchResultsRecord records and display them or write to another xml

    I made demo for you as a reference. (Because of elements: searchResultsList, response, Payload, IntegrationCBO.ProcessWCFServiceRs, responses , are not closed, I use my xml file).

    The code:

    XMl:
    
    <?xml version="1.0" standalone="yes"?>
    <Employees>
        <Employee Id="1" City="Seattle">
            <EmployeeName>Nancy Davolio</EmployeeName>
            <Country>USA</Country>
        </Employee>
        <Employee Id="2" City="Tacoma">
            <EmployeeName>Andrew Fuller</EmployeeName>
            <Country>USA</Country>
        </Employee>
        <Employee Id="3" City="Kirkland">
            <EmployeeName>Janet Leverling</EmployeeName>
            <Country>USA</Country>
        </Employee>
    </Employees>
    
    
    XmlDocument doc = new XmlDocument();
                doc.Load(@"C:\Users\samwu\Desktop\Test.xml");
                XmlNodeList nodeList = doc.SelectNodes("/Employees/Employee");
                foreach (XmlNode result in nodeList)
                {
                    var name = result["EmployeeName"].InnerText;
                    var country= result["Country"].InnerText;
                }

    The result:

    Best regards,

    Sam

    Friday, October 25, 2019 8:10 AM