Get values

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    #1

    Get values

    Hello,

    I am trying to load information from a XML file using only the nodes
    which attribute footer=true.

    I created the following code:

    Dim siteMap As New System.Xml.XmlD ocument
    siteMap.Load(Ht tpContext.Curre nt.Server.MapPa th(Me.SiteMapUr l))
    Dim siteMapNodeList As XmlNodeList =
    siteMap.SelectN odes("sitemapno de[@footer='true']")
    Dim iSiteMapNode As Integer

    ' Loop through each node in XML node list
    For iSiteMapNode = 0 To siteMapNodeList .Count - 1

    ' Create new hyperlink
    Dim link As New HyperLink

    ' Define hyperlink properties
    With link
    .ID = "by27f_h" &
    siteMapNodeList (iSiteMapNode). Attributes("tit le").Value
    .NavigateUrl =
    siteMapNodeList (iSiteMapNode). Attributes("url ").Value
    .Text =
    siteMapNodeList (iSiteMapNode). Attributes("tit le").Value
    .ToolTip =
    siteMapNodeList (iSiteMapNode). Attributes("tit le").Value
    End With

    Next

    I am not getting anything.

    My XML file is as follows:

    <?xml version="1.0" encoding="utf-8" ?>
    <siteMap
    xmlns = "http://schemas.microso ft.com/ASPNet/SiteMap-File-1.0" >
    <siteMapNode>
    <siteMapNode
    url = "~/Default.ASPx"
    title = "Home"
    description = "Desc1"
    footer = "true" />
    <siteMapNode
    url = "~/Contacts.ASPx"
    title = "Contactos"
    description = "Desc2"
    footer = "true" />
    </siteMapNode>
    </siteMap>

    Could you tell me what am I doing wrong?

    I can't understand why I don't get any values.

    Thanks,
    Miguel

  • Kevin Spencer

    #2
    Re: Get values

    Try using a System.Xml.XPat h.XPathNavigato r to navigate your XmlDocument, by
    using the CreateNavigator method:

    http://msdn2.microsoft.com/en-us/lib...navigator.aspx

    The XPathNavigator class allows you to navigate in all directions in an
    XmlDocument, using XPath expressions:

    http://msdn2.microsoft.com/en-us/lib...navigator.aspx

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Ministry of Software Development
    Thoughts and Ideas about programming, philosophy, science, arts, life, God, and related subjects.


    I just flew in from Chicago with
    a man with a wooden leg named Smith
    who shot an elephant in my pajamas.
    So I bit him.


    "shapper" <mdmoura@gmail. comwrote in message
    news:1163038046 .285521.116480@ i42g2000cwa.goo glegroups.com.. .
    Hello,
    >
    I am trying to load information from a XML file using only the nodes
    which attribute footer=true.
    >
    I created the following code:
    >
    Dim siteMap As New System.Xml.XmlD ocument
    siteMap.Load(Ht tpContext.Curre nt.Server.MapPa th(Me.SiteMapUr l))
    Dim siteMapNodeList As XmlNodeList =
    siteMap.SelectN odes("sitemapno de[@footer='true']")
    Dim iSiteMapNode As Integer
    >
    ' Loop through each node in XML node list
    For iSiteMapNode = 0 To siteMapNodeList .Count - 1
    >
    ' Create new hyperlink
    Dim link As New HyperLink
    >
    ' Define hyperlink properties
    With link
    .ID = "by27f_h" &
    siteMapNodeList (iSiteMapNode). Attributes("tit le").Value
    .NavigateUrl =
    siteMapNodeList (iSiteMapNode). Attributes("url ").Value
    .Text =
    siteMapNodeList (iSiteMapNode). Attributes("tit le").Value
    .ToolTip =
    siteMapNodeList (iSiteMapNode). Attributes("tit le").Value
    End With
    >
    Next
    >
    I am not getting anything.
    >
    My XML file is as follows:
    >
    <?xml version="1.0" encoding="utf-8" ?>
    <siteMap
    xmlns = "http://schemas.microso ft.com/ASPNet/SiteMap-File-1.0" >
    <siteMapNode>
    <siteMapNode
    url = "~/Default.ASPx"
    title = "Home"
    description = "Desc1"
    footer = "true" />
    <siteMapNode
    url = "~/Contacts.ASPx"
    title = "Contactos"
    description = "Desc2"
    footer = "true" />
    </siteMapNode>
    </siteMap>
    >
    Could you tell me what am I doing wrong?
    >
    I can't understand why I don't get any values.
    >
    Thanks,
    Miguel
    >

    Comment

    Working...