English 中文(简体)
linq to xml with namespace prefix
原标题:linq to xml with namespace prefix

页: 1

<Location xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Latitude>-1</Latitude>
<Longtitude>-1</Longtitude>
</Location>

如果没有名称空间(xmlns:i......),我可以使用以下询问。

//xdoc is an XDocument loaded with the above xml
var locCollection = from p in xdoc.Descendants("Location") 

我可以使用名称空间,但没有“一”预先规定。

XNamespace ns = @"http://www.w3.org/2001/XMLSchema-instance"
var locCollection = from p in xdoc.Descendants(ns + "Location")

因此,我如何处理牙齿“一”前??

Thanks.

最佳回答

问题是,当你提供名称空间之前,你需要明确预先确定位于该名称空间的XML要素。 因此,请在您的榜样中,明确指明标题如下: 然后,您的问询将发挥作用。

<i:Location xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
  <Latitude>-1</Latitude> 
  <Longtitude>-1</Longtitude> 
</i:Location> 

之所以没有预先确定,是因为在预先规定的情况下,指定名称空间被视为缺省名称空间,因此,<代码>Location在名称空间的缺省范围内。

问题回答

暂无回答




相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签