【问题标题】:Windows Mobile 5 Error reading XMLWindows Mobile 5 读取 XML 时出错
【发布时间】:2014-03-08 20:29:22
【问题描述】:

我无法获取以下 XML 的值

<ArrayOf    
   xmlns="http://schemas.datacontract.org/2004/07/WcfServicePedido_v7"
   xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
<V>    
<D>S</D> 
<I>Z</I> 
<V>1</V> </V> <V>    
<D>S</D>    
<I>Z</I> 
<V>2</V> </V>    
</ArrayOf>

我曾经看过以下代码:

XmlReader xmlReader = XmlReader.Create(url);

XDocument x = XDocument.Load(xmlReader);

var EmpData = from emp in x.Descendants("V")
              select new M
              {
                  V = Convert.ToInt32(emp.Descendants("V").First().Value),
                  I = emp.Descendants("I").First().Value,
                  D = emp.Descendants("D").First().Value
              };

List<M> aux = EmpData.ToList();

我无法获取值​​。 Empdata 为空。

【问题讨论】:

    标签: c# xml web-services rest windows-mobile-5.0


    【解决方案1】:

    您的 XML 有一个默认命名空间。

    // untested, from memory
    XDocument x = XDocument.Load(xmlReader);
    var ns = x.Root.GetDefaultnamespace();
    
    var EmpData = from emp in x.Descendants(ns + "V")
                  select new M
                  ...
                    Descendants(ns + "I")  
    

    【讨论】:

    • 也许你想发布一个可编译的、有效的答案。
    • 不,我不想那样做。
    • 好的,那么它只是一个评论。我会继续投反对票。
    • “只是评论”?你一定是在开玩笑。
    猜你喜欢
    • 2019-12-12
    • 2015-04-11
    • 1970-01-01
    • 2011-10-17
    • 2012-01-29
    • 2012-09-12
    • 1970-01-01
    • 2019-03-09
    • 1970-01-01
    相关资源
    最近更新 更多