I am struggling with a sensible logic loop for stripping out nodes from an XML file too large to use with XPath supporting .NET classes.
I am attempting to replace the single line of code I had (that called SelectNodes with an XPath query string) with code that does the same but uses an XmTextReader.
I have to go several levels down as illustraed by the previously used XPath quey (which was for reference):
ConfigurationRelease/Profiles/Profile[Name='MyProfileName']/Screens/Screen[Id='MyScreenId']/Settings/Setting[Name='MySettingName']
I thought this would be annoying but simple. However, I just can't seem to get the loop right.
I need to get a node, check a node under that to see if the value matches a target string and then walk down further if it does or skip that branch if it does't.
In fact, I think my problem is that I don't know how to ignore a branch if I'm not inetersted in it. I can't allow it to walk irrelevant branches as the element names are not unique (as illustrated by the XPath query).
I thought I could maintain some booleans e.g. bool expectingProfileName that gets set to true when I hit a Profile node. However, if its not the particular profile node I want, I can't get out of that branch.
So...hopefully this makes sense to someone...I've been staring at the problem for a couple hours and may just be missing something obvious.....
I'd like to post a portion of the file up but can't figure out how so the structure is roughly:
ConfigRelease > Profiles > Profile > Name > Screens > Screen > Settings > Setting > Name
I will know ProfileName, ScreenName and SettingName and I need the Setting node.
I am trying to avoid reading the whole file in one hit e.g. at app start-up because half the stuff in it won't ever be used. I also have no control over what generates the xml file so cannot change it to say, produce multiple smaller files.
Any tips will be greatly appreciated.
UPDATE
I have re-opened this. A poster suggested XPathDocument which should have been perfect. Unfortunatley, I didn't mention that this is a mobile app and XPathDocument is not supported.
The file isn't large by most standards which is why the system was originally coded to use XmlDocument. It is currently 4MB which is apparently large enough to crash a Mobile App when it is loaded into an XmlDocument. It's probably just as well it came up now as the file is epxected to get much bigger. Anyway, I am now trying the DataSet suggestion but am still open to other ideas.
UPDATE 2
I got suspiscious because quite a few people have said they would not expect a file this size to crash the system. Further experiments have shown that this is an intermittent crash. Yesterday it crashed everytime but this morning after I reset the device, I can't reproduce it. I am now trying to figure out a reliable set of reproductive steps. And also decide the best way to handle the problem which I'm sure is still there. I can't just leave it because if the app can't access this file, it is useless and I don't think can tell my users that they can't run anything else on their devices when my app is running.......