how to retrive data outside the html tag using vb.net

Dani AI

Generated

asked about extracting "data outside the html tag." That phrase can mean different things: the document preamble (DOCTYPE or XML prolog), invisible bytes (BOM), stray whitespace/comments, or extra text injected before/after the <html> element by server code. correctly hinted at looking at the preamble, and asked for clarification — below are practical VB.NET approaches and troubleshooting tips.

A quick, reliable method is to treat the page as plain text and slice around the first "<html" and the closing "</html>". That gives the raw content that precedes or follows the HTML root. For more structure and safety, load the page into an HTML parser (recommended over regex) and inspect the document node for child nodes that are not the <html> element.

Example: read raw text and extract before/after the html root.

Dim raw As String = File.ReadAllText("page.html", Encoding.UTF8)
Dim start As Integer = raw.IndexOf("<html", StringComparison.OrdinalIgnoreCase)
If start > 0 Then
    Dim before As String = raw.Substring(0, start)
    Console.WriteLine(before)
End If
Dim endIdx As Integer = raw.IndexOf("</html>", StringComparison.OrdinalIgnoreCase)
If endIdx >= 0 Then
    Dim after As String = raw.Substring(endIdx + 7)
    Console.WriteLine(after)
End If

Example: use Html Agility Pack to find nodes outside the root element.

Dim doc As New HtmlAgilityPack.HtmlDocument()
doc.Load("page.html", Encoding.UTF8)
For Each n As HtmlAgilityPack.HtmlNode In doc.DocumentNode.ChildNodes
    If Not String.Equals(n.Name, "html", StringComparison.OrdinalIgnoreCase) Then
        Console.WriteLine("Outside <html>: " & n.OuterHtml)
    End If
Next

Troubleshooting: if the content is invisible, check for a UTF-8 BOM (bytes EF BB BF) or stray server output (Global.asax, HttpModules, master pages, Response.Write calls). Use browser "view-source" or a traffic capture tool (curl/Fiddler) to see the raw response. Prefer a parser like Html Agility Pack for correctness; see Html Agility Pack documentation and the HTML/DOCTYPE notes on MDN for reference:

Html Agility Pack
MDN: Doctype

Recommended Answers

All 2 Replies

You'll have to be more descriptive. I didn't think there could be anything outside of HTML tags other than a DOCTYPE declaration.

Same way you search any text data I guess, put it in a string and RegEx (Reglar Expression) for what your looking for.

mention properly what u want....
i ain't gettin ur stuff!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.