English 中文(简体)
XMlSerialization is not seriesing a Annualtime
原标题:XMlSerialization is not serializing a Datetime

当我编造一个有<密码>的物体时,该物体在XML阵列中空投。

我的XSD、XSD产生的可序列类别以及处理XSD序列化的序列化辅助器。

<>XSD>:

 <?xml version="1.0" encoding="utf-8"?>
     <xs:schema id="test" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="testInformation">
       <xs:complexType>
        <xs:sequence>
             <xs:element name="DateOfBirth" minOccurs="0">
               <xs:simpleType>
                 <xs:restriction base="xs:date">
                   <xs:pattern value="d{4}-d{2}-d{2}" />
                 </xs:restriction>
               </xs:simpleType>
             </xs:element>
           </xs:sequence>
         </xs:complexType>
      </xs:element>
     </xs:schema>

<>Serializer:

     /// <summary>
         /// This static class provides methods which can be used to help with
 common xml serialiazation tasks.
         /// </summary>
         public static class XmlSerializationHelper
         {
                     public static string
 SerializeObject<ObjectToSerialize>(ObjectToSerialize
 obj)
             {
                 string responseXML = string.Empty;
                 using (MemoryStream ms = new MemoryStream())
                 using (StreamWriter output = new StreamWriter(ms,
 Encoding.UTF8))
                 using (StreamReader sr = new StreamReader(ms, Encoding.UTF8))
                 {
                     XmlSerializer xmlSerializer = new
 XmlSerializer(typeof(ObjectToSerialize));
                     xmlSerializer.Serialize(output, obj);
                     ms.Position = 0;

                     responseXML = sr.ReadToEnd();
                 }
                 return responseXML;
             }
         }

<>可再生类别>

     //------------------------------------------------------------------------------
     // <auto-generated>
     //     This code was generated by a tool.
     //     Runtime Version:2.0.50727.3607
     //
     //     Changes to this file may cause incorrect behavior and will be
 lost if
     //     the code is regenerated.
     // </auto-generated>
     //------------------------------------------------------------------------------

     // 
     // This source code was auto-generated by xsd,
 Version=2.0.50727.42.
     // 

         using System.Xml.Serialization;


         /// <remarks/>
         [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd",
 "2.0.50727.42")]
         [System.SerializableAttribute()]
         [System.Diagnostics.DebuggerStepThroughAttribute()]
         [System.ComponentModel.DesignerCategoryAttribute("code")]
         [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
         [System.Xml.Serialization.XmlRootAttribute(Namespace="",
 IsNullable=false)]
         public partial class testInformation {

             private System.DateTime dateOfBirthField;

             private bool dateOfBirthFieldSpecified;

             /// <remarks/>
             [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
             public System.DateTime DateOfBirth {
                 get {
                     return this.dateOfBirthField;
                 }
                 set {
                     this.dateOfBirthField = value;
                 }
             }

             /// <remarks/>
             [System.Xml.Serialization.XmlIgnoreAttribute()]
             public bool DateOfBirthSpecified {
                 get {
                     return this.dateOfBirthFieldSpecified;
                 }
                 set {
                     this.dateOfBirthFieldSpecified =
 value;
                 }
             }
         }

为什么将<代码>的数值编为空档?

最佳回答

您是否设置了<条码>DateOfBirth FieldSpecated至true? 它将违约到<代码>false,意思是:没有序列。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签