在 C# 中传递一个字符串

Posted

技术标签:

【中文标题】在 C# 中传递一个字符串【英文标题】:Pass a string in C# 【发布时间】:2021-02-07 08:08:43 【问题描述】:

我试图通过 C# 代码传递此字符串但失败:

soap:Body1479374

System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.LoadXml(string);

尝试发送整体和 3 个部分,但在 Sectiona 内失败

string Sectiona = @"soap:Body";

字符串 Sectionb = "1479374";

string Sectionc = "";

字符串数据 = Sectiona + Sectionb + Sectionc;

【问题讨论】:

【参考方案1】:

你的肥皂身体标签是错误的。使用 xml linq:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication1

    class Program
    
        static void Main(string[] args)
        
            string xml = "<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>1479374</soap:Body></soap:Envelope>";
            XDocument doc = XDocument.Parse(xml);
        
    

【讨论】:

以上是关于在 C# 中传递一个字符串的主要内容,如果未能解决你的问题,请参考以下文章