Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何反序列化xml中的非标准日期时间_Xml_Datetime_Xml Deserialization - Fatal编程技术网

如何反序列化xml中的非标准日期时间

如何反序列化xml中的非标准日期时间,xml,datetime,xml-deserialization,Xml,Datetime,Xml Deserialization,我正在尝试反序列化从服务呼叫中得到的一些响应。但是,响应包含一些不标准的日期时间格式。它抛出的字符串“13:37:53 2012年2月29日PST”不是有效的AllXsd值。我想知道是否有办法更改我的xmlreader或其他东西,以便反序列化它 <TimeCreated xsi:type="xs:dateTime">13:37:53 Feb 29, 2012 PST</TimeCreated> <TimeUpdated xsi:type="xs:dateTime"&

我正在尝试反序列化从服务呼叫中得到的一些响应。但是,响应包含一些不标准的日期时间格式。它抛出的字符串“13:37:53 2012年2月29日PST”不是有效的AllXsd值。我想知道是否有办法更改我的xmlreader或其他东西,以便反序列化它

<TimeCreated xsi:type="xs:dateTime">13:37:53 Feb 29, 2012 PST</TimeCreated>
<TimeUpdated xsi:type="xs:dateTime">13:37:53 Feb 29, 2012 PST</TimeUpdated>
13:37:53太平洋标准时间2012年2月29日
太平洋标准时间2012年2月29日13:37:53
这是我用来反序列化的代码

    public static T DeserializeFromXml<T>(string xml)
    {
        T result;
        XmlSerializer serializer = new XmlSerializer(typeof(T));
        using (TextReader txReader = new StringReader(xml))
        {
            // Create XmlReaderSettings
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ConformanceLevel = ConformanceLevel.Fragment;
            settings.IgnoreWhitespace = true;
            settings.IgnoreComments = true;

            // Create a new NameTable
            NameTable nt = new NameTable();

            // Create a new NamespaceManager
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);

            // Add your namespaces used in the XML
            nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
            nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
            // Create the XmlParserContext using the previous declared XmlNamespaceManager
            XmlParserContext ctx = new XmlParserContext(null, nsmgr, null, XmlSpace.None);

            // Instantiate a new XmlReader, using the previous declared XmlReaderSettings and XmlParserContext
            XmlReader reader = XmlReader.Create(txReader, settings, ctx);

            result = (T)serializer.Deserialize(reader);
        }
        return result;
    }
publicstatict反序列化fromXML(字符串xml)
{
T结果;
XmlSerializer serializer=新的XmlSerializer(typeof(T));
使用(TextReader txReader=new StringReader(xml))
{
//创建XmlReaderSettings
XmlReaderSettings设置=新建XmlReaderSettings();
settings.ConformanceLevel=ConformanceLevel.Fragment;
settings.IgnoreWhitespace=true;
settings.IgnoreComments=true;
//创建一个新的名称表
NameTable nt=新的NameTable();
//创建新的命名空间管理器
XmlNamespaceManager nsmgr=新的XmlNamespaceManager(nt);
//添加XML中使用的名称空间
nsmgr.AddNamespace(“xs”http://www.w3.org/2001/XMLSchema");
nsmgr.AddNamespace(“xsi”http://www.w3.org/2001/XMLSchema-instance");
//使用先前声明的XmlNamespaceManager创建XmlParserContext
XmlParserContext ctx=新的XmlParserContext(null,nsmgr,null,XmlSpace.None);
//使用先前声明的XmlReaderSettings和XmlParserContext实例化新的XmlReader
XmlReader=XmlReader.Create(txReader,设置,ctx);
结果=(T)序列化程序。反序列化(读取器);
}
返回结果;
}

我也在windows phone中工作,因此我需要一个在windows phone上运行的silverlight可用的解决方案。我想你不能只是说“这是一项非标准服务,所以我们不会使用它”?如果你真的不需要日期时间值,你可以将其解析为cdata,解析器将忽略它。我需要datetime值,但反序列化有问题。