none
How can I get data from an ArrayOffXElement RRS feed

  • Question

  • Hi, I'm calling a web service in Azure Function, which returns me an ArrayOfXElement type, but I don't know how to get to the data

    Thursday, November 21, 2019 1:00 PM

All replies

  • Hello,

    Use for for each where the iterator should be an XElement.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, November 21, 2019 2:12 PM
    Moderator
  • Hi alramirez7705,

    Thank you for posting here.

    For your question, you want to get data from a ArrayOfXelement.

    This is an example of ArrayOfXelement.

    <DataSet xmlns="http://tempuri.org/">
      <xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
        <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
          <xs:complexType>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
              <xs:element name="Table">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="ID" type="xs:int" minOccurs="0"/>
                    <xs:element name="classtitle" type="xs:string" minOccurs="0"/>
                    <xs:element name="classfile" type="xs:string" minOccurs="0"/>
                    <xs:element name="userName" type="xs:string" minOccurs="0"/>
                    <xs:element name="note" type="xs:string" minOccurs="0"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:choice>
          </xs:complexType>
        </xs:element>
      </xs:schema>
      <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
        <NewDataSet xmlns="">
          <Table diffgr:id="Table1" msdata:rowOrder="0">
            <ID>26</ID>
            <classtitle>tyu</classtitle>
            <classfile>E:\FTP\web\site\files\table1</classfile>
          </Table>
          <Table diffgr:id="Table2" msdata:rowOrder="1">
            <ID>27</ID>
            <classtitle>math</classtitle>
            <classfile>E:\FTP\web\site\files\table2</classfile>
          </Table>
          <Table diffgr:id="Table3" msdata:rowOrder="2">
            <ID>28</ID>
            <classtitle>science</classtitle>
            <classfile>C:\Users\Administrator\Desktop\mywebsite\table3</classfile>
          </Table>
          <Table diffgr:id="Table4" msdata:rowOrder="3">
            <ID>29</ID>
            <classtitle>ssz6</classtitle>
            <classfile>
              C:\Users\Administrator\Desktop\mywebsite\files\table4
            </classfile>
          </Table>
          <Table diffgr:id="Table5" msdata:rowOrder="4">
            <ID>30</ID>
            <classtitle>aa</classtitle>
            <classfile>
              C:\Users\Administrator\Desktop\mywebsite\files\table5
            </classfile>
          </Table>
        </NewDataSet>
      </diffgr:diffgram>
    </DataSet>

    For such a format, you can use Nodes.Descendants("Table") to get the label you want and then get the data through foreach.

    The following is a sample code.

                private async void FindAll()
                {
                    mywebservice.kechengbiaoSoapClient client = new mywebservice.kechengbiaoSoapClient();
                    ArrayOfXElement tables = await client.loadallclassAsync();
                    foreach (XElement el in tables.Nodes.Descendants("Table"))
                    {
                        ClassIndex table = new ClassIndex();
                        foreach (XElement ell in el.Nodes())
                        {
                            //  table.IndexId = Convert.ToInt32(ell.Value);                   
                            switch (Convert.ToString(ell.Name))
                            {
                                case "ID":
                                    table.IndexId = Convert.ToInt32(ell.Value);
                                    break;
                                case "classtitle":
                                    table.IndexTitle = ell.Value;
                                    break;
                                default:
                                    break;
                            }
                        }
                        data.Add(table);
                    }
                    listView.DataContext = data;
                }
    

    Hope this could be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Friday, November 22, 2019 2:13 AM