Solved

Modify and re parse bad XML data?

Posted on 2006-07-19
2
288 Views
Last Modified: 2010-08-05
Currently I load my XML in VS 2005 like this:
xmlDoc.Load(Url)
The XML returned is occasionally badly formed like below.

<?xml version="1.0" encoding="UTF-8" ?>
<chain ...>
 ... number of chain records ...
<?xml version="1.0" encoding="UTF-8" ?>
<error>
 ... description of what's wrong.
</error>

As you can see it's missing the closing tag </chain>.
Is it possible to modify the read XML data, remove the error part, add the closing chain tag and parse again?


This might be an alternative, so far I didn't try anything with it, still how to change the read data?

      Dim webRequest As System.Net.HttpWebRequest
      Dim webResponse As System.Net.HttpWebResponse
      webRequest = CType(System.Net.WebRequest.Create(Url), System.Net.HttpWebRequest)
      webRequest.AllowAutoRedirect = True
      webRequest.Timeout = DEF_TIMEOUT
      webResponse = CType(webRequest.GetResponse(), System.Net.HttpWebResponse)
      Dim sr As New System.IO.StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.UTF8)
      xmlDoc.Load(sr.ReadToEnd())
      sr.Close()
0
Comment
Question by:NicoLaan
2 Comments
 

Accepted Solution

by:
Zwabbert earned 250 total points
Comment Utility
Well, you're almost there.

Dim xml As String
xml = sr.ReadToEnd()
...
Code to change the XML string.
...
xmlDoc.LoadXml(xml)
0
 
LVL 4

Author Comment

by:NicoLaan
Comment Utility
Yeah, I'd figured that one out as well by now.
Still thanks for the good answer, you deserve the points.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now