J
John Williams
I'm using the WebBrowser control and Microsoft HTML Object Library
(MSHTML) in a VB .Net program. I'm trying to read <P> tags and their
contents from one HTML document, test1.htm, and insert them into
another, test2.htm. The problem is the relative URL in the <A> tag in
the 3rd paragraph.
test1.htm contains:
<HTML><HEAD></HEAD>
<BODY>
<P>This is the first paragraph</P>
<P>This is the second paragraph</P>
<P>This is the third paragraph with a <A
href="../../dir1/dir2/page2.htm">link</A> included</P>
</BODY>
</BODY>
test2.htm contains:
<HTML><HEAD></HEAD>
<BODY>
<HR>
</BODY>
</HTML>
The <P> tags are read from test1.htm and saved in a listbox using:
mElements = mDoc.getElementsByTagName("P")
For Each mElement In mElements
lstPTags.Items.Add(mElement.outerHTML)
Next
They are then inserted before the <HR> tag in test2.htm using:
For Each mElement In mDoc.all
If mElement.tagName = "HR" Then
For i = 0 To lstPTags.Items.Count - 1
mElement.insertAdjacentHTML("beforeBegin",
lstPTags.Items(i))
Next
End If
Next
This works fine, EXCEPT for the 3rd paragraph which contains an <A>
tag link. The link is converted from a relative URL to an absolute
URL in the modified test2.htm :
<P>This is the third paragraph with a <A
href="file:///C:/Documents%20and%20Settings/dir1/dir2/page2.htm">link</A>
included</P>
My question is: how can I copy and insert the <P> tag and embedded <A>
tag exactly as it appears in test1.htm into test2.htm?
(MSHTML) in a VB .Net program. I'm trying to read <P> tags and their
contents from one HTML document, test1.htm, and insert them into
another, test2.htm. The problem is the relative URL in the <A> tag in
the 3rd paragraph.
test1.htm contains:
<HTML><HEAD></HEAD>
<BODY>
<P>This is the first paragraph</P>
<P>This is the second paragraph</P>
<P>This is the third paragraph with a <A
href="../../dir1/dir2/page2.htm">link</A> included</P>
</BODY>
</BODY>
test2.htm contains:
<HTML><HEAD></HEAD>
<BODY>
<HR>
</BODY>
</HTML>
The <P> tags are read from test1.htm and saved in a listbox using:
mElements = mDoc.getElementsByTagName("P")
For Each mElement In mElements
lstPTags.Items.Add(mElement.outerHTML)
Next
They are then inserted before the <HR> tag in test2.htm using:
For Each mElement In mDoc.all
If mElement.tagName = "HR" Then
For i = 0 To lstPTags.Items.Count - 1
mElement.insertAdjacentHTML("beforeBegin",
lstPTags.Items(i))
Next
End If
Next
This works fine, EXCEPT for the 3rd paragraph which contains an <A>
tag link. The link is converted from a relative URL to an absolute
URL in the modified test2.htm :
<P>This is the third paragraph with a <A
href="file:///C:/Documents%20and%20Settings/dir1/dir2/page2.htm">link</A>
included</P>
My question is: how can I copy and insert the <P> tag and embedded <A>
tag exactly as it appears in test1.htm into test2.htm?