여기에 전체 작업 예제
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);
}
}
}
하여 출력
<AcknowledgementList xmlns="http://www.irs.gov/efile">
<Acknowledgement xmlns="http://www.irs.gov /efile">
<SubmissionId>4654652011356f7ovyf5</SubmissionId>
<EFIN>465465</EFIN>
<TaxYear>2011</TaxYear>
<GovernmentCode>OHST</GovernmentCode>
</Acknowledgement>
</AcknowledgementList>
어쩌면 당신은 당신이해야 할 기대에 대해 좀 더 정확한 될 수 있을까? 그 문자열이고 "efile"하위 문자열의 모든 항목을 제거 하시겠습니까? – ken2k
무엇을 의미합니까? 이것을 XML 또는 원시 문자열로 구문 분석 하시겠습니까? 지금까지 뭐라구? –
efile 접두사가없는 XmlDocument가 필요합니다 ... – jats