如何使用c#.net删除前缀 ********* 465465 2011 OHST
任何人都能告诉我从中删除前缀efile的最佳方法吗?这里是完整的工作示例如何使用c#.net删除前缀 ********* 465465 2011 OHST,c#,C#,任何人都能告诉我从中删除前缀efile的最佳方法吗?这里是完整的工作示例 <AcknowledgementList xmlns="http://www.irs.gov/efile" xmlns:efile="http://www.irs.gov /efile"> <efile:Acknowledgement> <efile:SubmissionId>*********</efile:SubmissionId> <ef
<AcknowledgementList xmlns="http://www.irs.gov/efile" xmlns:efile="http://www.irs.gov /efile">
<efile:Acknowledgement>
<efile:SubmissionId>*********</efile:SubmissionId>
<efile:EFIN>465465</efile:EFIN>
<efile:TaxYear>2011</efile:TaxYear>
<efile:GovernmentCode>OHST</efile:GovernmentCode>
</efile:Acknowledgement>
</AcknowledgementList>
使用系统;
使用System.Linq;
使用System.Xml.Linq;
命名空间控制台应用程序5
{
班级计划
{
静态void Main(字符串[]参数)
{
字符串xml=@“
4654652011356f7ovyf5
465465
2011
OHST
";
XDocument doc=XDocument.Parse(xml,LoadOptions.PreserveWhitespace);
doc.subjects().Attributes().Where(a=>a.IsNamespaceDeclaration).Remove();
xml=doc.ToString();
Console.WriteLine(xml);
}
}
}
你的产出
using System;
using System.Linq;
using System.Xml.Linq;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
string xml = @"<AcknowledgementList xmlns=""http://www.irs.gov/efile"" xmlns:efile=""http://www.irs.gov/efile"">
<efile:Acknowledgement>
<efile:SubmissionId>4654652011356f7ovyf5</efile:SubmissionId>
<efile:EFIN>465465</efile:EFIN>
<efile:TaxYear>2011</efile:TaxYear>
<efile:GovernmentCode>OHST</efile:GovernmentCode>
</efile:Acknowledgement>
</AcknowledgementList>";
XDocument doc = XDocument.Parse(xml, LoadOptions.PreserveWhitespace);
doc.Descendants().Attributes().Where(a => a.IsNamespaceDeclaration).Remove();
xml = doc.ToString();
Console.WriteLine(xml);
}
}
}
4654652011356f7ovyf5
465465
2011
OHST
这里是完整的工作示例
<AcknowledgementList xmlns="http://www.irs.gov/efile" xmlns:efile="http://www.irs.gov /efile">
<efile:Acknowledgement>
<efile:SubmissionId>*********</efile:SubmissionId>
<efile:EFIN>465465</efile:EFIN>
<efile:TaxYear>2011</efile:TaxYear>
<efile:GovernmentCode>OHST</efile:GovernmentCode>
</efile:Acknowledgement>
</AcknowledgementList>
使用系统;
使用System.Linq;
使用System.Xml.Linq;
命名空间控制台应用程序5
{
班级计划
{
静态void Main(字符串[]参数)
{
字符串xml=@“
4654652011356f7ovyf5
465465
2011
OHST
";
XDocument doc=XDocument.Parse(xml,LoadOptions.PreserveWhitespace);
doc.subjects().Attributes().Where(a=>a.IsNamespaceDeclaration).Remove();
xml=doc.ToString();
Console.WriteLine(xml);
}
}
}
你的产出
using System;
using System.Linq;
using System.Xml.Linq;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
string xml = @"<AcknowledgementList xmlns=""http://www.irs.gov/efile"" xmlns:efile=""http://www.irs.gov/efile"">
<efile:Acknowledgement>
<efile:SubmissionId>4654652011356f7ovyf5</efile:SubmissionId>
<efile:EFIN>465465</efile:EFIN>
<efile:TaxYear>2011</efile:TaxYear>
<efile:GovernmentCode>OHST</efile:GovernmentCode>
</efile:Acknowledgement>
</AcknowledgementList>";
XDocument doc = XDocument.Parse(xml, LoadOptions.PreserveWhitespace);
doc.Descendants().Attributes().Where(a => a.IsNamespaceDeclaration).Remove();
xml = doc.ToString();
Console.WriteLine(xml);
}
}
}
4654652011356f7ovyf5
465465
2011
OHST
也许您可以更精确地说明您希望做什么?这是一个字符串,您想删除所有出现的“efile”子字符串吗?什么意思?您想将其解析为XML还是原始字符串?到目前为止,您得到了什么?我想要没有efile前缀的XmlDocument…为什么要删除前缀??它的存在是有原因的——不要反抗——拥抱它!如果删除这些namespacde前缀,您将更改文档,这意味着您可以更精确地了解您希望执行的操作?这是一个字符串,您想删除所有出现的“efile”子字符串吗?什么意思?您想将其解析为XML还是原始字符串?到目前为止,您得到了什么?我想要没有efile前缀的XmlDocument…为什么要删除前缀??它的存在是有原因的——不要反抗——拥抱它!如果删除这些namespacde前缀,则会更改文档的含义