Results 1 to 7 of 7

Thread: Problem Parsing XML

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2003
    Location
    Amsterdam, The Netherlands
    Posts
    53

    Problem Parsing XML

    I hava problem where my code breaks when it encounters low-ASCII (01-32 decimal) in any node when this is run:

    Code:
                XDoc = New XmlDocument
    
                If flgrp = 0 Then filepath = RecCasepath & "\Playlists\"_
     & filepath
                XDoc.Load(filepath)
                RCgroup = XDoc.DocumentElement.SelectNodes("//media")
    Anything below 20 hex causes an exception. I know where the problem comes from, but I need to catch this as it stems from an older version of the software writing the XML and many people wtill have this error in their XML files..

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    VB Code:
    1. Try
    2.  
    3. XDoc = New XmlDocument
    4.  
    5. If flgrp = 0 Then filepath = RecCasepath & "\Playlists\"_
    6.  & filepath
    7.  XDoc.Load(filepath)
    8. RCgroup = XDoc.DocumentElement.SelectNodes("//media")
    9.  
    10. Catch
    11.  
    12.  
    13.         Catch ex As Exception
    14.             MessageBox.Show(ex.Message)
    15.         End Try

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2003
    Location
    Amsterdam, The Netherlands
    Posts
    53
    I know what that's going to show.. '01hex is an invalid character'

    But it will break of parsing the XML file, I woudl like to prevent that if I can..

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Prevent what ? the error or the error handler ?

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2003
    Location
    Amsterdam, The Netherlands
    Posts
    53
    I would like to prevent the exception.. Right now my code will skip the file with the problem, but I would like to skip the node with the problem if I can.. but it seems the exception is thrown when

    RCgroup = XDoc.DocumentElement.SelectNodes("//media")


    is executed, so I do not know if I can (I am guessing I cannot using this method..)

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    1-
    Try this ,
    VB Code:
    1. On Error Resume Next
    2.  
    3.  
    4. XDoc = New XmlDocument
    5.  
    6. If flgrp = 0 Then filepath = RecCasepath & "\Playlists\"_
    7.  & filepath
    8.  XDoc.Load(filepath)
    9. RCgroup = XDoc.DocumentElement.SelectNodes("//media")

    2-
    and you can handle the exception but don't need to show it in a messagebox . This will continue your program execution flow .

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2003
    Location
    Amsterdam, The Netherlands
    Posts
    53
    That will prevent the exception, but still skip the erroneous file.. I prefer to be able to tell what went wrong so I have an excuse..

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