Here is a snippet of XML:
<AssignmentHistory Version="210002" DateLastPurged="2020-12-11"> <W20190107> <Teaching> <Name Class="1">Brother 1</Name> <Name Class="2">Brother 2</Name> <Name Class="3">Brother 3</Name> </Teaching> </W20190107> <W20190114> <Teaching> <Name Class="1">Brother 1</Name> <Name Class="2">Brother 2</Name> <Name Class="3">Brother 3</Name> </Teaching> </W20190114> </AssignmentHistory> I realise that my use of WYYYYMMDD for the element name was not very clever. I designed the XML file when I was only learning XML / XSL and now see it not to be good.
The above is stripped down just to show what I need to show.
I know I can do a path query like this:
XmlDocument doc = new XmlDocument(); doc.Load("file.xml"); XmlNodeList nl = doc.SelectNodes("AssignmentHist/*/Teaching"); ... And it will return all of the Teaching elements in a XmlNodeList.
The XML file is sorted in descending date order and what I would like to do is use a query that will select all teaching nodes where the date is greater than a specified value. At the moment I have to:
- Iterate the complete list
- Get the name of the parent node (
WYYYYMMDD) - Strip the leading
W - Extract the
YYYY,MM&DDcomponents - Build a
DateTimeobject and compare the date of interest againstxxxx.Date.
It would be nice if the single select query could put all of those out. But can it be done?
https://stackoverflow.com/questions/65568644/building-a-select-query-to-isolate-all-nodes-with-a-date-greater-than January 05, 2021 at 03:27AM
没有评论:
发表评论