TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Lee Blake
NA
18
0
XPath NodeIterator not able to iterate through results.
Feb 26 2014 5:04 AM
I have some XML that is stored in the database and passed in as a string to my method.
<settings>
<ReportOptions>
<ReportWidget>
<widget Name="Report Exclusions">
<Visibility>
<VisibilitySetting Name="ClosedLocations" Value="true"/>
</Visibility>
</widget>
<widget Name="Report Period">
<Visibility>
<VisibilitySetting Name="Day" Value="true"/>
<VisibilitySetting Name="Month" Value="true"/>
</Visibility>
</widget>
<widget Name="Output Method">
<Properties>
<Visibility>
<VisibilitySetting Name="Report Viewer" Value="true"/>
<VisibilitySetting Name="Pdf" Value="true"/>
</Visibility>
</Properties>
</widget>
</ReportWidget>
</ReportOptions>
</settings>
I run the following expression in an online XPath tester:
/settings/ReportOptions/ReportWidget/widget[@Name='Output Method']/Properties/Visibility/VisibilitySetting[@Name]
and I get the following results:
<?xml version="1.0" encoding="UTF-8"?>
<result>
<VisibilitySetting Name="Report Viewer" Value="true"/>
<VisibilitySetting Name="Pdf" Value="true"/>
</result>
But when I run the following code:
var customizationApplied = false;
var firstProperty = Items[0];
var settings = firstProperty.Widget.Report.Settings;
var widgetName = firstProperty.Widget.Name;
// Select the node and place the results in an iterator
var strExpression = settings.Compile("/settings/ReportOptions/ReportWidget/widget[@Name='Output Method']/Properties/Visibility/VisibilitySetting[@Name]");
var nodeIterator = settings.Select(strExpression);
// iterate through the results
while (nodeIterator.MoveNext())
{
var xmlPropertyName = nodeIterator.Current.GetAttribute("Name", string.Empty);
var propertyToCustomize = (from prop in Items
where string.Equals(prop.Name, xmlPropertyName, StringComparison.OrdinalIgnoreCase)
select prop).FirstOrDefault();
if (propertyToCustomize != null)
{
var xmlPropertyValue = nodeIterator.Current.GetAttribute("Value", string.Empty);
propertyToCustomize.IsEnabled = StringToObjectHelper.GetValue(xmlPropertyValue, false);
customizationApplied = true;
}
}
I get no results. The nodeIterator always shows this on the mouseover:
Position=0, Current={Root}
and when I execute the nodeIterator.MoveNext() method, it returns false.
Can anyone please shed some light on what the problem could be? It all worked before and nothing has been changed.
Thanks,
Lee
Reply
Answers (
1
)
Login
Asp.Net MVC+EF+Oracle