루트 태그를 제외한 모든 XML 요소에서이 xmlns = "http://www.AB.com/BC/QualityDeviationCase/1_0"을 제거하고 싶습니다. C#을 사용하여 XML 요소. xml 형식으로 코드를 작성하려면 아래 코드를 작성하십시오. 그러나 XML 요소에서 xmlns 태그를 제거 할 수 없습니다.cml을 사용하여 xml 요소에서 xmlns 태그를 제거하는 방법 #
<?xml version="1.0" encoding="utf-16"?>
<QualityDeviationCaseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CaseID xmlns="http://www.AB.com/BC/QualityDeviationCase/1_0">2</CaseID>
<Description xmlns="http://www.AB.com/BC/QualityDeviationCase/1_0">Air filter is not present</Description>
<StartDate xmlns="http://www.AB.com/BC/QualityDeviationCase/1_0">0001-01-01T00:00:00</StartDate>
<LastUpdated xmlns="http://www.AB.com/BC/QualityDeviationCase/1_0">0001-01-01T00:00:00</LastUpdated>
</QualityDeviationCaseType>
이후의 xmlns = "http://www.AB.com/BC/QualityDeviationCase/1_0"이 태그를 제거, 내 결과는
<?xml version="1.0" encoding="utf-16"?>
<QualityDeviationCaseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CaseID>2</CaseID>
<Description>Air filter is not present</Description>
<StartDate>0001-01-01T00:00:00</StartDate>
<LastUpdated>0001-01-01T00:00:00</LastUpdated>
</QualityDeviationCaseType>
내 C# 코드 below-으로 다음과 같이 반환해야 , 내 XSD 파일에서 XML 결과를 얻고있다.
connection.Open();
adapter = new SqlDataAdapter(sql, connection);
adapter.Fill(dt);
myTestTable = dt.Clone();
DataRow[] orderRows = dt.Select();
XmlDocument xmlDoc = new XmlDocument();
QualityDeviationCaseType oQualityDeviationCaseType = new QualityDeviationCaseType();
foreach (DataRow row in orderRows)
{
oQualityDeviationCaseType = new QualityDeviationCaseType();
oQualityDeviationCaseType.CaseID = row[0].ToString();
oQualityDeviationCaseType.Description = row[3].ToString();
}
using (StringWriter stringwriter = new System.IO.StringWriter())
{
XmlSerializer ser = new XmlSerializer(typeof(QualityDeviationCaseType));
ser.Serialize(stringwriter, oQualityDeviationCaseType);
sampleChannel.Publish(stringwriter.ToString());
//This line of code sending my xml file to IBM WMQ.
}
필자의 위 코드에 따르면, 각 결과마다 XML 태그가 포함되어 있습니다. C#을 사용하여 요소 태그에서 제거하고 싶습니다.