Results 1 to 8 of 8

Thread: XmlNode SelectSingleNode filter criteria not working

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2016
    Posts
    41

    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.
    Name:  xml error.jpg
Views: 406
Size:  32.3 KB
    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.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,458

    Re: XmlNode SelectSingleNode filter criteria not working


  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,458

    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)

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2016
    Posts
    41

    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.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,458

    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

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,748

    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" />
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,458

    Re: XmlNode SelectSingleNode filter criteria not working

    Quote Originally Posted by dbasnett View Post
    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…

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,748

    Re: XmlNode SelectSingleNode filter criteria not working

    Quote Originally Posted by .paul. View Post
    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.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width