LINQ to XML. Enumeration yielded no results?
I cannot figure out why Enumeration does not yield any results
Dim Configuration = From Setup In XElement.Load("C:\xml\setup.xml").Elements("settings")
Select Setup
For Each Setting As String In Configuration
'Do something
Next
And here is the Xml file located at C:/xml/setup.xml
<?xml version="1.0" encoding="utf-8"?>
<settings>
<columns>10</columns>
<rows>3</rows>
<thumbWidth>1024</thumbWidth>
<thumbHeight>开发者_JS百科768</thumbHeight>
<thumbPadding>40</thumbPadding>
<videoWidth>181</videoWidth>
<videoHeight>136</videoHeight>
<CaptionPosition>top</CaptionPosition>
<Autoplay>no</Autoplay>
<Delay>6</Delay>
<Target>_blank</Target>
</settings>
What am i doing wrong here?
You've called XElement.Load
, which will return the settings
element itself. In other words, you're currently looking for elements called settings
inside the settings
element.
Options:
- Use
XDocument.Load
instead - Just use the loaded
XElement
itself, instead of callingElements
- with thesettings
element being the root element, there can only be one of them anyway. Make your XML document have a root element, e.g.
<root> <settings> ... </settings> <settings> ... </settings> </root>
精彩评论