我遇到问题,我必须删除封闭标签,我的操作合同是:
public List<MessageStatus> sendMessages(List<MessageTO> messages)
和在SOAPUI输出中添加后形成的XML如下所示:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sms="https://sms.responsetek.com/">
<soapenv:Header/>
<soapenv:Body>
<sms:sendMessages>
<!--Optional:-->
<sms:messages>
<!--Zero or more repetitions:-->
<message>
<mid>?</mid>
<oa>?</oa>
<da>?</da>
<text>?</text>
<!--Optional:-->
<exp>?</exp>
</message>
</sms:messages>
</sms:sendMessages>
</soapenv:Body>
</soapenv:Envelope>
我想从中删除<sms:messages>
标记。
答案 0 :(得分:0)
请尝试以下操作:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication69
{
class Program
{
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
XElement messages = doc.Descendants().Where(x => x.Name.LocalName == "messages").FirstOrDefault();
messages.Remove();
}
}
}