本文介绍了如何在c#中的Xmldocument中获取webresponse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WebResponse response = req.GetResponse();



流responseStream =(response.GetResponseStream());

XmlDocument xDoc = new XmlDocument();



XmlTextReader myXMLReader = null;

myXMLReader = new XmlTextReader(response.GetResponseStream());



xDoc.Load(myXMLReader);



在myXMLReader中我得到的只有xDoc确实有innertext作为xml文档。

i想使用这个xdoc创建一个数据表,但节点没有被选中。

我使用下面的代码,但它总是假设我的xdoc中有数据。



int f =(xDoc.SelectNodes(// Result / node()))。计数;



我的xmldocument(xDoc)文档类似于

< s:Envelope xmlns:s =http://schemas.xmlsoap.org/soap/envelope/> < s:Body>< SearchResponse xmlns =http://stellatravelgateway.stellatravel services.co.uk/AirService\"><SearchResult Success =trueErrorCode =0ErrorDescription =ResultSetID =41584558-7197-4d79-a45b-17a83c1936b3xmlns:xsi =http:// www .w3.org / 2001 / XMLSchema-instancexmlns:xsd =http://www.w3.org/2001/XMLSchema><结果><结果>< AirResult ResultItemID =0运营商= BAFrom =LGWTo =BCNFromName =London Gatwick,London,Great BritainToName =Barcelona,Barcelona,SpainAirlineClass =OOperatorName =British AirwaysCabinClass =EconomyHasAvailability =trueFareType =已发布MinStayCode =MaxStayCode =MinStayDescription =MaxStayDescription =AdultGross =61.50AdultTax =78.59AdultTotal =140.09AdultCommission =0.00ChildGross =61.50 ChildTax =78.59ChildTotal =140.09ChildCommission =0.00InfantGross =10.00InfantTax =37.59InfantTotal =47.59InfantCommission =0.00TotalGross =133.00TotalCommission =0.00TotalTax =194.77 AdultPaxCount =1ChildPaxCount =1InfantPaxCount =1><条件> ....... .... 





ifound这个命名空间行是crteating问题。

 < SearchResponse xmlns =http://stellatravelgateway.stellatravelservices.co.uk/AirService> 





i想要使用foreach循环在节点上。



怎么办这个

请帮助

解决方案

WebResponse response = req.GetResponse();

Stream responseStream = (response.GetResponseStream());
XmlDocument xDoc = new XmlDocument();

XmlTextReader myXMLReader = null;
myXMLReader = new XmlTextReader(response.GetResponseStream());

xDoc.Load(myXMLReader);

In myXMLReader i m getting none but xDoc do have innertext as xml document.
i wan to use this xdoc to create a datatable but nodes doesnot get selected.
I use following code but it give 0 always inspite of having data in my xdoc.

int f = (xDoc.SelectNodes("//Result/node()")).Count;

my xmldocument(xDoc) document is like

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><SearchResponse xmlns="http://stellatravelgateway.stellatravelservices.co.uk/AirService"><SearchResult Success="true" ErrorCode="0" ErrorDescription="" ResultSetID="41584558-7197-4d79-a45b-17a83c1936b3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Results><Result><AirResult ResultItemID="0" Operator="BA" From="LGW" To="BCN" FromName="London Gatwick, London, Great Britain" ToName="Barcelona, Barcelona, Spain" AirlineClass="O" OperatorName="British Airways" CabinClass="Economy" HasAvailability="true" FareType="Published" MinStayCode="" MaxStayCode="" MinStayDescription="" MaxStayDescription="" AdultGross="61.50" AdultTax="78.59" AdultTotal="140.09" AdultCommission="0.00" ChildGross="61.50" ChildTax="78.59" ChildTotal="140.09" ChildCommission="0.00" InfantGross="10.00" InfantTax="37.59" InfantTotal="47.59" InfantCommission="0.00" TotalGross="133.00" TotalCommission="0.00" TotalTax="194.77" AdultPaxCount="1" ChildPaxCount="1" InfantPaxCount="1"><Conditions>...........



ifound that this namespace line is crteating problem .

<SearchResponse xmlns="http://stellatravelgateway.stellatravelservices.co.uk/AirService">



i want to use foreach loop on nodes.

what to do with this
Please help

解决方案


这篇关于如何在c#中的Xmldocument中获取webresponse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 18:06