-
Feb 4th, 2023, 04:13 PM
#1
Thread Starter
Junior Member
XmlNode SelectSingleNode filter criteria not working
Hi all,
Many thanks in advance for any help given, it is much appreciated.
Please see attached code and XML file in the attached image.

Please can someone advise on this?
EDIT... im not sure if the text is visible enough in the attachment... if not, see below:
Code:
Dim BendProcesses As XmlNode = doc.SelectSingleNode("/BendPart/BendProcesses/BendProcess['BendId=4']/AxisPositions/LinearAxisPosition['AxisName=ZB1']")
MsgBox(BendProcesses.Attributes("RawValue").Value)
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<BendPart box:version="1.0" Name="3 MS 100+50+200+50+50 tophat 135deg x 1000 long" Properties="M|fc3fdae9-1b5b-4812-8d4b-cd4866fe26fd|By%20Steel|3|a1dd1a04-c5c4-4e2d-965b-fb5cfcd9bfba|Xpert-150x3100-EH100-RFA-T12-HA6-AK" Thickness="3" xmlns:box="http://www.bystronic.com/bysoft7/scheme">
<BendProcesses>
<BendProcess SheetHandling="Flip" BendId="3" BendAngle="135.0" BendDeduction="4782" ProcessOrder="1" ProcessGroup="3">
<AxisPositions>
<LinearAxisPosition AxisName="AK1" RawValue="323" />
<LinearAxisPosition AxisName="AK2" RawValue="233" />
<LinearAxisPosition AxisName="ZB1" RawValue="2334" />
<LinearAxisPosition AxisName="ZB2" RawValue="252" />
</AxisPositions>
</BendProcess>
<BendProcess SheetHandling="Flip" BendId="4" BendAngle="135.0" BendDeduction="1.86999035782" ProcessOrder="1" ProcessGroup="3">
<AxisPositions>
<LinearAxisPosition AxisName="AK1" RawValue="1753" />
<LinearAxisPosition AxisName="AK2" RawValue="1754" />
<LinearAxisPosition AxisName="ZB1" RawValue="1107.49969055" />
<LinearAxisPosition AxisName="ZB2" RawValue="1992.50030945" />
</AxisPositions>
</BendProcess>
</BendProcesses>
</BendPart>
Thank you.
Last edited by sijcooke; Feb 4th, 2023 at 05:39 PM.
-
Feb 4th, 2023, 08:59 PM
#2
Re: XmlNode SelectSingleNode filter criteria not working
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 4th, 2023, 09:44 PM
#3
Re: XmlNode SelectSingleNode filter criteria not working
This worked for me...
Code:
Dim doc As New Xml.XmlDocument
doc.Load("C:\pathTo\test.xml")
'Create an XmlNamespaceManager for resolving namespaces.
Dim nsmgr As Xml.XmlNamespaceManager = New Xml.XmlNamespaceManager(doc.NameTable)
nsmgr.AddNamespace("bp", "box=http://www.bystronic.com/bysoft7/scheme")
Dim root As Xml.XmlElement = doc.DocumentElement
Dim BP As Xml.XmlNode = root.SelectSingleNode("//BendProcess[@BendId='4']/AxisPositions/LinearAxisPosition[@AxisName='ZB1']")
MsgBox(BP.Attributes("RawValue").Value)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 5th, 2023, 04:43 PM
#4
Thread Starter
Junior Member
Re: XmlNode SelectSingleNode filter criteria not working
Thanks for the replies... .paul. thats sorted it.. thank you. Im not sure how you mark it as solved. Thank you.
-
Feb 6th, 2023, 02:46 AM
#5
Re: XmlNode SelectSingleNode filter criteria not working
At the top of this thread, above your original question, to the right, there’s a Thread Tools menu with an option to mark as RESOLVED
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 6th, 2023, 09:38 AM
#6
Re: XmlNode SelectSingleNode filter criteria not working
Using XElement and LINQ
The data
Code:
Dim doc As XElement
' doc = XElement.Load("path here")
' for testing use literal
doc = <BendPart box:version="1.0" Name="3 MS 100+50+200+50+50 tophat 135deg x 1000 long" Properties="M|fc3fdae9-1b5b-4812-8d4b-cd4866fe26fd|By%20Steel|3|a1dd1a04-c5c4-4e2d-965b-fb5cfcd9bfba|Xpert-150x3100-EH100-RFA-T12-HA6-AK" Thickness="3" xmlns:box="http://www.bystronic.com/bysoft7/scheme">
<BendProcesses>
<BendProcess SheetHandling="Flip" BendId="3" BendAngle="135.0" BendDeduction="4782" ProcessOrder="1" ProcessGroup="3">
<AxisPositions>
<LinearAxisPosition AxisName="AK1" RawValue="323"/>
<LinearAxisPosition AxisName="AK2" RawValue="233"/>
<LinearAxisPosition AxisName="ZB1" RawValue="2334"/>
<LinearAxisPosition AxisName="ZB2" RawValue="252"/>
</AxisPositions>
</BendProcess>
<BendProcess SheetHandling="Flip" BendId="4" BendAngle="135.0" BendDeduction="1.86999035782" ProcessOrder="1" ProcessGroup="3">
<AxisPositions>
<LinearAxisPosition AxisName="AK1" RawValue="1753"/>
<LinearAxisPosition AxisName="AK2" RawValue="1754"/>
<LinearAxisPosition AxisName="ZB1" RawValue="1107.49969055"/>
<LinearAxisPosition AxisName="ZB2" RawValue="1992.50030945"/>
</AxisPositions>
</BendProcess>
</BendProcesses>
</BendPart>
The code
Code:
Dim BendProcesses As XElement
BendProcesses = (From el In doc...<BendProcess>
Where el.@BendId = "4"
From bp In el...<LinearAxisPosition>
Where bp.@AxisName = "ZB2"
Select bp Take 1).FirstOrDefault
' BendProcesses = <LinearAxisPosition AxisName="ZB2" RawValue="1992.50030945" />
-
Feb 6th, 2023, 11:55 AM
#7
Re: XmlNode SelectSingleNode filter criteria not working
 Originally Posted by dbasnett
Using XElement and LINQ
The data
Code:
Dim doc As XElement
' doc = XElement.Load("path here")
' for testing use literal
doc = <BendPart box:version="1.0" Name="3 MS 100+50+200+50+50 tophat 135deg x 1000 long" Properties="M|fc3fdae9-1b5b-4812-8d4b-cd4866fe26fd|By%20Steel|3|a1dd1a04-c5c4-4e2d-965b-fb5cfcd9bfba|Xpert-150x3100-EH100-RFA-T12-HA6-AK" Thickness="3" xmlns:box="http://www.bystronic.com/bysoft7/scheme">
<BendProcesses>
<BendProcess SheetHandling="Flip" BendId="3" BendAngle="135.0" BendDeduction="4782" ProcessOrder="1" ProcessGroup="3">
<AxisPositions>
<LinearAxisPosition AxisName="AK1" RawValue="323"/>
<LinearAxisPosition AxisName="AK2" RawValue="233"/>
<LinearAxisPosition AxisName="ZB1" RawValue="2334"/>
<LinearAxisPosition AxisName="ZB2" RawValue="252"/>
</AxisPositions>
</BendProcess>
<BendProcess SheetHandling="Flip" BendId="4" BendAngle="135.0" BendDeduction="1.86999035782" ProcessOrder="1" ProcessGroup="3">
<AxisPositions>
<LinearAxisPosition AxisName="AK1" RawValue="1753"/>
<LinearAxisPosition AxisName="AK2" RawValue="1754"/>
<LinearAxisPosition AxisName="ZB1" RawValue="1107.49969055"/>
<LinearAxisPosition AxisName="ZB2" RawValue="1992.50030945"/>
</AxisPositions>
</BendProcess>
</BendProcesses>
</BendPart>
The code
Code:
Dim BendProcesses As XElement
BendProcesses = (From el In doc...<BendProcess>
Where el.@BendId = "4"
From bp In el...<LinearAxisPosition>
Where bp.@AxisName = "ZB2"
Select bp Take 1).FirstOrDefault
' BendProcesses = <LinearAxisPosition AxisName="ZB2" RawValue="1992.50030945" />
In this case, I don’t see any great advantage of using LINQ over XPath…
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 6th, 2023, 12:19 PM
#8
Re: XmlNode SelectSingleNode filter criteria not working
 Originally Posted by .paul.
In this case, I don’t see any great advantage of using LINQ over XPath…
For me personally I like the clarity of the query, but I'm sure the XPath statement is as clear to you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|