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. C#
  4. Help in selecting attributes with XPath [modified]

Help in selecting attributes with XPath [modified]

Scheduled Pinned Locked Moved C#
cssdesignxmlhelpquestion
2 Posts 2 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.
  • S Offline
    S Offline
    student_rhr
    wrote on last edited by
    #1
    <field name="textBox" y="3.175" x="3.17" w="62" h="9">
      <ui>
        <textBox>
          <border>
            <css style="">            </css>
          </border>
          <margin/>
        </textBox>
      </ui>
      <font face="Arial"/>
      <margin topInset="1" bottomInset="1" leftInset="1" rightInset="1"/>
      <textAlign vAlign="middle"/>
      <label reserve="25">
        <Font fontFace="Arial" size="8pt" />
        <textAlign vAlign="middle"/>
        <value>
          <text>textbox label</text>
        </value>
      </label>
    </field>
    

    So I am trying to read the values of Font (IF there is a textBox element present) and trying to read the attributes fontFace and size, here is my Xpath:

                XPathNodeIterator iterator = nav.Select(@"/field");
                try
                {
                    while (iterator.MoveNext())
                    {
                        //Do some other stuff
                        ...
                        XPathNavigator nav2 = iterator.Current.Clone();
                        if (string.Compare(nav2.Name, "field") == 0)
                        {
                        XPathNodeIterator textBoxIterator = nav2.Select("child::*/child::textBox");
    
                        if (textBoxIterator.Count > 0)
                        {
                            XPathExpression exp = nav2.Compile("child::Font");
                            XPathNodeIterator it = nav2.Select(exp);
    
                            while (it.MoveNext())
                            {
                                XPathNavigator nav3 = it.Current.Clone();
                                string fontFace = nav3.GetAttribute("typeface", nav3.NamespaceURI);
                                string fontSize = nav3.GetAttribute("size", nav3.NamespaceURI);
                            }
                        }
                    }
                 }
                 catch
    ...
    }
    

    Am I doing it the proper way or is it too complicated and can be simplified?

    modified on Tuesday, March 4, 2008 10:22 AM

    C 1 Reply Last reply
    0
    • S student_rhr
      <field name="textBox" y="3.175" x="3.17" w="62" h="9">
        <ui>
          <textBox>
            <border>
              <css style="">            </css>
            </border>
            <margin/>
          </textBox>
        </ui>
        <font face="Arial"/>
        <margin topInset="1" bottomInset="1" leftInset="1" rightInset="1"/>
        <textAlign vAlign="middle"/>
        <label reserve="25">
          <Font fontFace="Arial" size="8pt" />
          <textAlign vAlign="middle"/>
          <value>
            <text>textbox label</text>
          </value>
        </label>
      </field>
      

      So I am trying to read the values of Font (IF there is a textBox element present) and trying to read the attributes fontFace and size, here is my Xpath:

                  XPathNodeIterator iterator = nav.Select(@"/field");
                  try
                  {
                      while (iterator.MoveNext())
                      {
                          //Do some other stuff
                          ...
                          XPathNavigator nav2 = iterator.Current.Clone();
                          if (string.Compare(nav2.Name, "field") == 0)
                          {
                          XPathNodeIterator textBoxIterator = nav2.Select("child::*/child::textBox");
      
                          if (textBoxIterator.Count > 0)
                          {
                              XPathExpression exp = nav2.Compile("child::Font");
                              XPathNodeIterator it = nav2.Select(exp);
      
                              while (it.MoveNext())
                              {
                                  XPathNavigator nav3 = it.Current.Clone();
                                  string fontFace = nav3.GetAttribute("typeface", nav3.NamespaceURI);
                                  string fontSize = nav3.GetAttribute("size", nav3.NamespaceURI);
                              }
                          }
                      }
                   }
                   catch
      ...
      }
      

      Am I doing it the proper way or is it too complicated and can be simplified?

      modified on Tuesday, March 4, 2008 10:22 AM

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      //field/font@fontFace I believe, and you can put something in [] to specific a condition, such as where there's a sibling node called textbox.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      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