1. <small id='vlw3K'></small><noframes id='vlw3K'>

      <bdo id='vlw3K'></bdo><ul id='vlw3K'></ul>

    1. <legend id='vlw3K'><style id='vlw3K'><dir id='vlw3K'><q id='vlw3K'></q></dir></style></legend>
    2. <i id='vlw3K'><tr id='vlw3K'><dt id='vlw3K'><q id='vlw3K'><span id='vlw3K'><b id='vlw3K'><form id='vlw3K'><ins id='vlw3K'></ins><ul id='vlw3K'></ul><sub id='vlw3K'></sub></form><legend id='vlw3K'></legend><bdo id='vlw3K'><pre id='vlw3K'><center id='vlw3K'></center></pre></bdo></b><th id='vlw3K'></th></span></q></dt></tr></i><div id='vlw3K'><tfoot id='vlw3K'></tfoot><dl id='vlw3K'><fieldset id='vlw3K'></fieldset></dl></div>
      <tfoot id='vlw3K'></tfoot>

    3. 如何让 XMLSerializer 将命名空间添加到嵌套对象中的属性?

      How do I get the XMLSerializer to add namespaces to attributes in nested objects?(如何让 XMLSerializer 将命名空间添加到嵌套对象中的属性?)

        • <tfoot id='T408X'></tfoot>
          <i id='T408X'><tr id='T408X'><dt id='T408X'><q id='T408X'><span id='T408X'><b id='T408X'><form id='T408X'><ins id='T408X'></ins><ul id='T408X'></ul><sub id='T408X'></sub></form><legend id='T408X'></legend><bdo id='T408X'><pre id='T408X'><center id='T408X'></center></pre></bdo></b><th id='T408X'></th></span></q></dt></tr></i><div id='T408X'><tfoot id='T408X'></tfoot><dl id='T408X'><fieldset id='T408X'></fieldset></dl></div>
          • <bdo id='T408X'></bdo><ul id='T408X'></ul>
            <legend id='T408X'><style id='T408X'><dir id='T408X'><q id='T408X'></q></dir></style></legend>

            <small id='T408X'></small><noframes id='T408X'>

                  <tbody id='T408X'></tbody>
                本文介绍了如何让 XMLSerializer 将命名空间添加到嵌套对象中的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                这是我得到的:

                <ex:test soap:mustUnderstand="1" xmlns:ex="http://www.example.com/namespace">
                  <ex:A Type="lorem">ipsum</ex:A>
                </ex:test>
                

                这就是我想要的:(注意 Type-attribute 的前缀是 ex.)

                This is what I want: (Note that the Type-attribute is prefixed with ex.)

                <ex:test soap:mustUnderstand="1" xmlns:ex="http://www.example.com/namespace">
                  <ex:A ex:Type="lorem">ipsum</ex:A>
                </ex:test>
                

                这是我的代码:

                  [XmlType(Namespace = "http://www.example.com/namespace")]
                  [XmlRoot("ex", Namespace = "http://www.example.com/namespace")]
                  public class TestSoapHeader : SoapHeader {
                    private TestSoapHeaderTypeValuePair _a;
                
                    public TestHeader() {
                      MustUnderstand = true;
                    }
                
                    [XmlNamespaceDeclarations]
                    public XmlSerializerNamespaces xmlsn {
                      get {
                        XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
                        xsn.Add("ex", "http://www.example.com/namespace");
                        return xsn;
                      }
                      set { }
                    }
                
                    public TestSoapHeaderTypeValuePair A {
                      get { return _a; }
                      set { _a = value; }
                    }
                
                  }
                
                  [XmlType(Namespace = "http://www.example.com/namespace")]
                  public class TestSoapHeaderTypeValuePair {
                    private string _type;
                    private string _value;
                
                    [XmlNamespaceDeclarations]
                    public XmlSerializerNamespaces xmlsn
                    {
                      get
                      {
                        XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
                        xsn.Add("ex", "http://www.example.com/namespace");
                        return xsn;
                      }
                      set { }
                    }
                
                    public TestSoapHeaderTypeValuePair(string type, string value) {
                      Type = type;
                      Value = value;
                    }
                
                    public TestSoapHeaderTypeValuePair() {}
                
                    [System.Xml.Serialization.XmlAttributeAttribute("type", Namespace = "http://www.example.com/namespace")]
                    public string Type {
                      get { return _type; }
                      set { _type = value; }
                    }
                
                    [System.Xml.Serialization.XmlText()]
                    public string Value {
                      get { return _value; }
                      set { _value = value; }
                    }
                  }
                

                推荐答案

                IXmlSerializable 可能吗?

                注意我还添加了(到A):

                Note I also added (to A):

                [XmlElement("A", Namespace = "http://www.example.com/namespace")]
                public TestSoapHeaderTypeValuePair A {...}
                

                代码如下:

                public class TestSoapHeaderTypeValuePair : IXmlSerializable
                {
                    private string _type;
                    private string _value;
                
                    public TestSoapHeaderTypeValuePair(string type, string value)
                    {
                        Type = type;
                        Value = value;
                    }
                
                    public TestSoapHeaderTypeValuePair() { }
                
                    public string Type
                    {
                        get { return _type; }
                        set { _type = value; }
                    }
                
                    public string Value
                    {
                        get { return _value; }
                        set { _value = value; }
                    }
                
                    #region IXmlSerializable Members
                
                    System.Xml.Schema.XmlSchema IXmlSerializable.GetSchema()
                    {
                        return null;
                    }
                
                    void IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
                    {
                        throw new NotImplementedException();
                    }
                
                    void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer)
                    {
                        writer.WriteAttributeString("ex", "type", "http://www.example.com/namespace", Type);
                        writer.WriteString(Value);
                    }
                
                    #endregion
                }
                

                这篇关于如何让 XMLSerializer 将命名空间添加到嵌套对象中的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                Accessing attribute info from DTE(从 DTE 访问属性信息)
                c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                How can I force the PropertyGrid to show a custom dialog for a specific property?(如何强制 PropertyGrid 显示特定属性的自定义对话框?)
                Associate attribute with code generated property in .net(将属性与 .net 中的代码生成属性相关联)
                <tfoot id='8FK5L'></tfoot>

                    <tbody id='8FK5L'></tbody>
                  <legend id='8FK5L'><style id='8FK5L'><dir id='8FK5L'><q id='8FK5L'></q></dir></style></legend>
                  • <bdo id='8FK5L'></bdo><ul id='8FK5L'></ul>
                  • <small id='8FK5L'></small><noframes id='8FK5L'>

                    <i id='8FK5L'><tr id='8FK5L'><dt id='8FK5L'><q id='8FK5L'><span id='8FK5L'><b id='8FK5L'><form id='8FK5L'><ins id='8FK5L'></ins><ul id='8FK5L'></ul><sub id='8FK5L'></sub></form><legend id='8FK5L'></legend><bdo id='8FK5L'><pre id='8FK5L'><center id='8FK5L'></center></pre></bdo></b><th id='8FK5L'></th></span></q></dt></tr></i><div id='8FK5L'><tfoot id='8FK5L'></tfoot><dl id='8FK5L'><fieldset id='8FK5L'></fieldset></dl></div>