Afternoon,
I've been looking around for code that can do this for a few days and all the samples I find use an XDocument.View node select method as part of the code. I don't actually have all of the nodes that I want to look at in the views that I am calling the function from, so (as far as I understand it - which isn't very far) that is why this code does not work for me.
This is VBScript. I have tried a number of different methods but can't get one to work. My first attempt involved view but I think I got the XPath wrong and as discussed earlier don't think I can use View anyway. I also can't get XDocument.DOM.CreateNavigator to work as I found in other examples.
My data source is structured as follows:
-
myFields
-
Hardware (Repeating)
-
Software (Repeating)
-
Order (Repeating)
-
HWID (Repeating)
-
SWID (Repeating)
There are many other fields but these are the important ones at the moment. Each order is populated with hardware/software that was filled in in the other two lists. If the number of items in Hardware or Software is zero I want to remove all items in HWID or SWID lists respectively so as to avoid confusion with less observant users.
Does anyone have any suggestions on how I might go about this? 2 examples of my many attempts are below and fail miserably.
I have tried:
Dim objNode
Dim objNodes
Dim ordNodes
Dim ordObjNodes
objNode = XDocument.DOM.selectSingleNode ("//my:myFields/my:Hardware")
XDocument.View.SelectNodes objXMLNode
objNodes = XDocument.View.GetSelectedNodes
objNode = XDocument.DOM.selectSingleNode ("//my:myFields/my:Order")
XDocument.View.SelectNodes objXMLNode
ordNodes = XDocument.View.GetSelectedNodes
objNode = XDocument.DOM.selectSingleNode ("//my:myFields/my:Order/my:HWID")
XDocument.View.SelectNodes objXMLNode
ordObjNodes = XDocument.View.GetSelectedNodes
if objNodes.Count > 0 Then
'If there are hardware items, make sure there is at least one in the orders
Else
'If there are no hardware items, remove all hardware items from the orders
End If
And:
xpn = XDocument.Dom.CreateNavigator
hNode = xpn.selectSingleNode ("//my:myFields/my:Hardware", NamespaceManager)
oNode = xpn.selectSingleNode ("//my:myFields/my:Order", NamespaceManager)
idNode = XDocument.GetNamedNodeProperty (oNode,"my:HWID","Unknown")
if hNode.Count > 0 Then
'If there are hardware items, make sure there is at least one in the orders
Else
'If there are no hardware items, remove all hardware items from the orders
End If