Script to Search XML Files for open tags?

Author Message
Malcz86

  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 1/10/2012
  • Status: offline
Script to Search XML Files for open tags? Wednesday, January 11, 2012 12:19 AM (permalink)
0
Been trying to find a way to write a script which searches a XML file for a open tag. The XML file is a log and when the job is being run the XML file is incomplete. For example there's a <Tag1> but not a </Tag1>. I've tried using XML DOM to search the XML file for open tags have have had no luck.
 
Any ideas would be appreciated.
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: online
    Re:Script to Search XML Files for open tags? Wednesday, January 11, 2012 6:02 AM (permalink)
    0
    I'm not sure how the VBS regex engine will handle it, but try this regex:
     
    "^((?:<(\w++)[^>]*+(?<!/)>(?1)</\2?|[^<>]++|<\w[^>]*+/>)*+)$"
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      59cobalt

      • Total Posts : 979
      • Scores: 91
      • Reward points : 0
      • Joined: 7/17/2011
      • Status: offline
      Re:Script to Search XML Files for open tags? Wednesday, January 11, 2012 6:08 AM (permalink)
      0
      Trying to load an incomplete XML structure into an XML DOM object should cause a parse error, because the XML is invalid.
      Set xml = CreateObject("MSXML.DOMDocument")
      xml.Async = False
      xml.ValidateOnParse = True
      xml.Load "C:\foo.xml"
      WScript.Echo xml.ParseError

       
      #3
        ebgreen

        • Total Posts : 8227
        • Scores: 98
        • Reward points : 0
        • Joined: 7/12/2005
        • Status: online
        Re:Script to Search XML Files for open tags? Wednesday, January 11, 2012 6:13 AM (permalink)
        0
        Oh yeah, if you just want to verify that the xml is valid, go with 59cobalt's suggestion.
        "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
        Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
        http://www.visualbasicscript.com/m_47117/tm.htm
         
        #4
          Malcz86

          • Total Posts : 2
          • Scores: 0
          • Reward points : 0
          • Joined: 1/10/2012
          • Status: offline
          Re:Script to Search XML Files for open tags? Wednesday, January 11, 2012 11:50 PM (permalink)
          0
          Thanks, the parse error solution does what I need.
           
          I can use the xml.parseerror.reason and a IF/Instr statement to output what tag's open.
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9