Results 1 to 2 of 2

Thread: VB.NET: Extract Xml attribute related to symbol

  1. #1

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230

    VB.NET: Extract Xml attribute related to symbol

    Say i have these Xml tag...
    Code:
    <book title=”Harry Porter  page="1_9”>
        <new id=”100”>China News</new>
        <new id=”101”>Street paper</new>
        <new id=”0”>none</it>
        …….
        <new>….</new>
      </book>
    how do i exactly extract the 1 and 10 separately from "1_9"

    Now i am using substring to extract 1 and 9, it works well...

    But if the 9 becomes 10 (double digits), it will have exception if i have to loop the Xml and send the maxpage to the server...

    Code:
    page = xdoc.SelectSingleNode("//book/@page").Value.Substring(0, 1)
    maxPage = xdoc.SelectSingleNode("//book/@page").Value.Substring(2, 1)
    Thanks

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Re: VB.NET: Extract Xml attribute related to symbol

    Use the underscore to parse the string into the 2 components, i.e.

    VB Code:
    1. Dim value as String = xdoc.SelectSingleNode("//book/@page").Value
    2.       Dim page As String = value.Substring(0, value.IndexOf("_"))
    3.       Dim maxPage As String = value.Substring(value.IndexOf("_") + 1)

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