お世話になります。
###前提・実現したいこと
前提:XmlSerializerでXMLを生成したときに要素に属性"xmlns"が付与される。
実現したいこと:要素の属性"xmlns"をはずしたい。
###発生している問題・エラーメッセージ
XmlSerializerでXMLを生成したときに要素に属性"xmlns"が付与されています。
・・・
<Parent1 xmlns="">
<child1>aa</child1>
</Parent1>
<Parent2 xmlns="">
<child2>bb</child2>
</Parent2>
・・・
Parent1,Parent2要素にある属性xmlnsは仕様書にないものなので、生成時に付与されないようにしたい。
###該当のソースコード
(Typeはxsdから生成したクラスです。)
StreamWriter sw = new StreamWriter(Path, false, Encoding.UTF8);
XmlSerializer serializer = new XmlSerializer(typeof(Type));
serializer.Serialize(sw, obj);
###補足情報(言語/FW/ツール等のバージョンなど)
IDEとしてVisualStudio C#を使用しています。
C#、XMLについては浅学のため、不足している情報がありましたらすみません。
追記:
xsdから自動生成したType.csになります。
namespace TEST {
using System.Xml.Serialization;
/// <remarks/> [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="test.jp")] [System.Xml.Serialization.XmlRootAttribute(Namespace="test.jp", IsNullable=false)] public partial class Type { private Parent parentField; /// <remarks/> [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] public Parent1 parent1 { get { return this.parent1Field; } set { this.parent1Field = value; } } } [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace="test.jp")] public partial class Parent { private string child1Field; /// <remarks/> [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] public string child1 { get { return this.child1Field; } set { this.child1Field = value; } } }
}
回答2件
あなたの回答
tips
プレビュー