开发者

XML to Gridview if possible?

开发者 https://www.devze.com 2023-03-19 09:43 出处:网络
Good day, I am going to try be as breif but informative as possible, I am using asp.net 3.5 and C#, basically what I am attempting to do is collect information from a xml file I recieve from a HTTPReq

Good day, I am going to try be as breif but informative as possible, I am using asp.net 3.5 and C#, basically what I am attempting to do is collect information from a xml file I recieve from a HTTPRequest. However using the usual dataset.readxml is not working for me. Please take a minute to look through everything before posting any answers.

I recieve xml that looks like this: (I have removed some information but am happy to supply the full XML set that I recieve as I am trying not to spam this with rubbish info)

    <SEGMENTS>
<SEGMENT NAME="webcluster">
    <RESULTPAGE>
        <QUERYTRANSFORMS>
            <QUERYTRANSFORM NAME="Original query" ACTION="NOP" QUERY="printers" CUSTOM="" MESSAGE="Original query" MESSAGEID="1"/>
            <QUERYTRANSFORM NAME="FastQT_Lemmatizer" ACTION="nop" QUERY="" CUSTOM="No change to query" MESSAGE="Lemmatization turned off for current query" MESSAGEID="16" INSTANCE="lemmatizer"/>
            <QUERYTRANSFORM NAME="Final query" ACTION="NOP" QUERY="string("printers")" CUSTOM="FQL" MESSAGE="Final query" MESSAGEID="1"/>
        </QUERYTRANSFORMS>
        <NAVIGATION ENTRIES="0">
        </NAVIGATION>
        <CLUSTERS/>
        <RESULTSET FIRSTHIT="1" LASTHIT="1" HITS="1" TOTALHITS="1121" MAXRANK="6610" TIME="0.0000">
            <HIT NO="1" RANK="6610" SITEID="0" MOREHITS="0" FCOCOUNT="0">
                <FIELD NAME="body"/>
                <FIELD NAME="customerid">36547986</FIELD>
                <FIELD NAME="name">Yahunn Digital <key>Printers</key></FIELD>
                <FIELD NAME="itemcode">DTRJ</FIELD>
                <FIELD NAME="bookcode">155512</FIELD>
                <FIELD NAME="heading">BANNERS</FIELD>
                <FIELD NAME="link2">15530694.GIF</FIELD>
            </HIT>
        </RESULTSET>
        <PAGENAVIGATION>
            <NEXTPAGE FIRSTHIT="2" LASTHIT="2" URL="/cgi-bin/xml-search?开发者_如何学Pythonquery=printers&hits=1&offset=1"/>
        </PAGENAVIGATION>
    </RESULTPAGE>
</SEGMENT>

I attempt to read it using the following:

    HttpWebRequest request = WebRequest.Create(builder.Uri) as HttpWebRequest;
        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
        {
            // Get the response stream  
            StreamReader readerSR = new StreamReader(response.GetResponseStream());

            // Console application output  
            //lblReturn.Text = readerSR.ReadToEnd().ToString();
            DataSet XMLDataSet = new DataSet();
            XMLDataSet.ReadXml(readerSR);
            dgvResults.DataSource = XMLDataSet.Tables[9].DefaultView;
            dgvResults.DataBind();
        }; 

But the simple answer is that this does not return a proper set of information to populate the gridview with. The table XMLDataSet.Tables[7].Rows.Count.ToString() contains 223 rows, which is completely incorrect, with the xml I gave that is 1 result(ofcourse I left out 216 "fields" which are returned for the example) but it seems it is creating a row for each "FIELD". My question is, how would I either get the information into a DataGridView, or should I be doing something enirely different to display this information? The reason I would like to use a gridview is purely because I am confrtable with the customization of a gridview.


You have a wrong XML schema so you cant read the XML file so the problem that you cant load the XML. please try to fix xml schema befor render to grid view

QUERY="string("printers")" => QUERY="string('printers')"

Note that the '&' destroy the XML and cause a render error so i used to replace it by %26%.

and the close tag for the root tag [SEGMENTS]

hope this will help you

0

精彩评论

暂无评论...
验证码 换一张
取 消