如何使用C#将字符串值作为参数传递给xmldocument? [英] How to pass a string value as parameter in an xmldocument using C#?
本文介绍了如何使用C#将字符串值作为参数传递给xmldocument?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用带有c#的asp.net在XmlDocument中传递一个字符串值作为参数。我动态调用Web服务并传递请求Xml作为参数(strReqXml)。 strReqXml变量将包含Request Xml作为字符串。
我的代码如下:
I want to pass a string value as parameter in an XmlDocument using asp.net with c#. I am calling a web service dynamically and passing a request Xml as parameter(strReqXml) . strReqXml variable will contain Request Xml as string.
My code is as below:
string strReqXml = BuildReqXML(dt, ref UniqueRefno);
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
<ShipmentResponse xmlns=""http://tempuri.org/"">
<parameter1>
tEST
</parameter1>
</ShipmentResponse>
</soap:Body>
</soap:Envelope>");
我的尝试:
What I have tried:
string strReqXml = BuildReqXML(dt, ref UniqueRefno);
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
<ShipmentResponse xmlns=""http://tempuri.org/"">
<parameter1>
tEST
</parameter1>
</ShipmentResponse>
</soap:Body>
</soap:Envelope>");
推荐答案
如果您修复了xmlns之前的空格,它应该可以正常工作。你可以尝试.. ??
Space before "xmlns" is missing if you fix that, it should work. Can you try..??
doc.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
<ShipmentResponse xmlns=""http://tempuri.org/"">
<parameter1>
tEST
</parameter1>
</ShipmentResponse>
</soap:Body>
</soap:Envelope>");
这篇关于如何使用C#将字符串值作为参数传递给xmldocument?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文