Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XPath query C#

XPath query C#

Scheduled Pinned Locked Moved XML / XSL
xmlcsharpdatabasetutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abcxyz82
    wrote on last edited by
    #1

    Below is the sample xml analgous to mine, "============= ... ===========" Now, I am trying write a function which says an employee with name xxx belongs to Dept xxx or not? taking two parameters, DEPT_NODE and EMPNAME as parameters. I can not change the signature as its from top. how to write an Xpath query for that? Thanks for anticipation. Regards. MaulikCE

    i don want

    D 1 Reply Last reply
    0
    • A abcxyz82

      Below is the sample xml analgous to mine, "============= ... ===========" Now, I am trying write a function which says an employee with name xxx belongs to Dept xxx or not? taking two parameters, DEPT_NODE and EMPNAME as parameters. I can not change the signature as its from top. how to write an Xpath query for that? Thanks for anticipation. Regards. MaulikCE

      i don want

      D Offline
      D Offline
      DavidNohejl
      wrote on last edited by
      #2
      bool isInDepartment( string department, string employee );
      XpathDocument doc= new XPathDocument();
      doc.Load( ... );
      
      XPathExpression exp = new XPathExpression( string.format("//DEPT[@name={0}]/EMP[@name={1}]", department, employee) );
      
      return !( null == doc.SelectSingleNode( exp ) );
      

      Or better take a look at SelectSingleNode[^]. Never forget: "Stay kul and happy" (I.A.)
      David's thoughts / dnhsoftware.org / MyHTMLTidy

      A 1 Reply Last reply
      0
      • D DavidNohejl
        bool isInDepartment( string department, string employee );
        XpathDocument doc= new XPathDocument();
        doc.Load( ... );
        
        XPathExpression exp = new XPathExpression( string.format("//DEPT[@name={0}]/EMP[@name={1}]", department, employee) );
        
        return !( null == doc.SelectSingleNode( exp ) );
        

        Or better take a look at SelectSingleNode[^]. Never forget: "Stay kul and happy" (I.A.)
        David's thoughts / dnhsoftware.org / MyHTMLTidy

        A Offline
        A Offline
        abcxyz82
        wrote on last edited by
        #3

        Thanks David, My requirement is little different, I have reference to DEPT node so I have to search relatively from DEPT as other branches may also have same departments. In terms of code, bool isInDepartment( XmlElement eleDept, string employee ); What could be the XPath query for this?

        J 1 Reply Last reply
        0
        • A abcxyz82

          Thanks David, My requirement is little different, I have reference to DEPT node so I have to search relatively from DEPT as other branches may also have same departments. In terms of code, bool isInDepartment( XmlElement eleDept, string employee ); What could be the XPath query for this?

          J Offline
          J Offline
          Jon Hulatt
          wrote on last edited by
          #4

          If you can't work out your xpath from the help dnh gave you, then I really suggest you go and buy an xml book and read it. At the very least, run through the w3schools tutorial http://www.w3schools.com/xpath/default.asp, which will take you all of 5 minutes, rather than want someone else to write your code for you.

          using System.Beer;

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups