doc.loadxml(axwebbrowser1.document.body.outerhtml),不起作用? [英] doc.loadxml(axwebbrowser1.document.body.outerhtml) , doesn't work?

查看:61
本文介绍了doc.loadxml(axwebbrowser1.document.body.outerhtml),不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在自动导航网站。当我到达终点时,它会变成xml。


所以我的axwebbrowser1里面有一堆xml数据。

所以这就是我想做的事情


Dim xmlText As String

Dim doc As New XmlDocument()

Dim myElem As XmlElement

xmlText = AxWebBrowser1.Document.Body.OuterHTML

doc.LoadXml(xmlText)


但问题是我在

doc.loadxml(xmltext)中得到一个异常错误

我找到了一个streamreader示例,但我已经在

axwebbrowser控件。


如何获取它以便我可以解析节点?


感谢您的任何信息

解决方案

整个文档是什么样的?


要么在这里发布,要么给出网址我们可以看到。


thx,


史蒂夫

" MeNotHome" < dtfa @ **** **** nospm&insightbb.com GT;在消息中写道

新闻:c7 ******************************** @ 4ax.com ...

我正在自动导航网站。当我到达终点时,它会改变为xml。

所以我的axwebbrowser1里面有一堆xml数据。

所以这就是我想要的做什么

Dim xmlText As String
Dim doc As New XmlDocument()
Dim myElem As XmlElement
xmlText = AxWebBrowser1.Document.Body.OuterHTML
doc.LoadXml(xmlText)

但问题是我在
doc.loadxml(xmltext)上出现异常错误
我找到了一个streamreader示例,但我已经有了xml
axwebbrowser控件中的数据。

如何获取它以便我可以解析节点?

感谢您提供任何信息


我希望我可以发布网站,但它是在受密码保护的网站上。

但这是在ie6中查看的页面。


<?xml version =" 1.0"编码= QUOT; ISO-8859-1" ?>

- < ShipmentForecasts>

- < ShipmentForecast>

< extract-datetime

code =" CST"> 2003-10-15T15:33:06.000-06:00< / extract-datetime>

< FileKey> ALL1 * 23759 * 20011200 * ALL1< / FileKey>

< TransactionIdentification> 000343717< / TransactionIdentification>

< ReleaseIdentification Type =" Original"

DateType =" Delivery"> 20011200< / ReleaseIdentification>

< DateTime> 2003-10-15T21:33:06.000Z< / DateTime>

< StartDateTime> 2003-10-13T21:33 :06.000Z< / StartDateTime>

< EndDateTime> 2004-10-06T00:00:00.000Z< / EndDateTime>

- < ShipFrom>

- <公司>

等等....


这有帮助吗?


感谢您提供任何建议。


周一,2003年10月20日11:42:55 -0500,史蒂夫 < as*@abc.com>写道:

整个文档是什么样的?

要么在这里发布,要么给出我们可以看到的网址。

thx,

史蒂夫

" MeNotHome" < dtfa @ **** **** nospm&insightbb.com GT;在消息中写道
新闻:c7 ******************************** @ 4ax.com ..。< blockquote class =post_quotes>我正在自动导航网站。当我到达终点时,它会改变为xml。

所以我的axwebbrowser1里面有一堆xml数据。

所以这就是我想要的做什么

Dim xmlText As String
Dim doc As New XmlDocument()
Dim myElem As XmlElement
xmlText = AxWebBrowser1.Document.Body.OuterHTML
doc.LoadXml(xmlText)

但问题是我在
doc.loadxml(xmltext)上出现异常错误
我找到了一个streamreader示例,但我已经有了xml
axwebbrowser控件中的数据。

如何获取它以便我可以解析节点?

感谢您提供任何信息




你知道......这对我来说很好看。我没有看到任何错误。什么

处于异常状态?


这里有一些快速代码这将有助于你在此期间解析xml ...我没有时间去了解新的xml内容如何在.net中工作所以这是

my 5分钟问题解决了适应。


hth,


史蒂夫


私有子xmlParsing()

Dim xml As String

xml& ="< authorization>" &安培; vbCrLf

xml& =" < RECORD1>" &安培; vbCrLf

xml& =" <编号→1< / ID>" &安培; vbCrLf

xml& =" <作用大于1< /角色>" &安培; vbCrLf

xml& =" < description>系统帐户< / description>" &安培; vbCrLf

xml& =" < / RECORD1>" &安培; vbCrLf

xml& =" < RECORD2>" &安培; vbCrLf

xml& =" < ID> 2'; / ID>" &安培; vbCrLf

xml& =" <作用> 2'; /角色>" &安培; vbCrLf

xml& =" <描述>管理员< /描述>" &安培; vbCrLf

xml& =" < / RECORD2>" &安培; vbCrLf

xml& =" < RECORD3>" &安培; vbCrLf

xml& =" < ID> 3'; / ID>" &安培; vbCrLf

xml& =" <作用> 3'; /角色>" &安培; vbCrLf

xml& =" < description>标准用户< / description>" &安培; vbCrLf

xml& =" < / RECORD3>" &安培; vbCrLf

xml& ="< / authorization>" &安培; vbCrLf

xml& ="< authorization>" &安培; vbCrLf

xml& =" < RECORD4>" &安培; vbCrLf

xml& =" < ID> 4℃; / ID>" &安培; vbCrLf

xml& =" <作用> 4℃; /角色>" &安培; vbCrLf

xml& =" < description>系统旋钮< / description>" &安培; vbCrLf

xml& =" < / RECORD4>" &安培; vbCrLf

xml& =" < record5>" &安培; vbCrLf

xml& =" < ID> 5℃; / ID>" &安培; vbCrLf

xml& =" <作用> 5℃/角色>" &安培; vbCrLf

xml& =" < description> Certified looser< / description>" &安培; vbCrLf

xml& =" < / record5>" &安培; vbCrLf

xml& =" < record6>" &安培; vbCrLf

xml& =" <编号→6< / ID>" &安培; vbCrLf

xml& =" <角色→6< /角色>" &安培; vbCrLf

xml& =" < description> emmense whiner< / description>" &安培; vbCrLf

xml& =" < / record6>" &安培; vbCrLf

xml& ="< / authorization>" &安培; vbCrLf

Dim authorization()As String = getMultipleSegments(" AUTHORIZATION&qu​​ot;,xml)

如果授权什么都没有那么返回

Dim segment As字符串

对于每个段在授权中

Dim records()As String = getMultipleSegments(" RECORD",segment)

如果不是记录是什么都没有

昏暗的描述为字符串

Dim id为整数

Dim record As String

Dim role As String

For each record in records

id = CInt(getSegmentValue(getSingleSegment(" ID",record),0))

role = getSegmentValue(getSingleSegment(" ROLE",record))

description = getSegmentValue(getSingleSegment(" DESCRIPTION&qu​​ot;,record))

Console.WriteLine(" id: & id&",role:"& role&",description:"&

description)

Next

结束如果

下一页

缺点ole.ReadLine()

结束子


私函数getMultipleSegments(ByVal segment As String,ByVal xml As

String)As String()

如果xml为Nothing则退出函数

Dim pattern As String ="< \s *" &安培;细分市场" [^>] *>。* LT; \s * / \s *" &安培;细分&

" [^>] *?>"

Dim regExp作为新的正则表达式(模式,RegexOptions.ExplicitCapture或

RegexOptions.Singleline或RegexOptions.IgnoreCase)

如果不是regExp.IsMatch(xml)那么退出函数

Dim match As Match

Dim result()As String

Dim index As Integer

For each match in regExp.Matches(xml)

ReDim Preserve result(index)

结果(指数)= match.Value

指数+ = 1

下一页

返回结果

结束函数


私函数getSingleSegment(ByVal segment As String,ByVal xml As

String)As String

如果xml是Nothing则退出函数

Dim pattern As String ="< \s *" &安培;细分市场" [^>] *>。* LT; \s * / \s *" &安培;细分&

" [^>] *?>"

Dim regExp作为新的正则表达式(模式,RegexOptions.ExplicitCapture或

RegexOptions.Singleline或RegexOptions.IgnoreCase)

如果不是regExp.IsMatch(xml)那么退出函数

Dim match As Match = regExp.Match(xml)

返回match.Value

结束函数


私有重载函数getSegmentValue(ByVal xml As String)As String

如果xml是Nothing则退出函数

Dim pattern As String ="< [^>] *>"

Dim regExp As New Regex(模式)

如果不是regExp.IsMatch(xml)那么退出函数

返回regExp.Replace(xml,"")

结束函数


私有重载函数getSegmentValue(ByVal xml As String,ByVal

emptyDefault As String)As String

Dim value As String = getSegmentValue(xml)

如果值为Nothing OrElse value.Trim = vbNullString则value =

emptyDefault

返回值

结束功能

" MeNotHome" < dtfa @ **** **** nospm&insightbb.com GT;在消息中写道

news:6e ******************************** @ 4ax.com ...

我希望我可以发布网站,但它是在受密码保护的网站上。
但这是在ie6中查看时页面的样子。

<?xml version =" 1.0"编码= QUOT; ISO-8859-1" ?>
- < ShipmentForecasts>
- < ShipmentForecast>
< extract-datetime
code =" CST"> 2003-10-15T15:33: 06.000-06:00< / extract-datetime>
< FileKey> ALL1 * 23759 * 20011200 * ALL1< / FileKey>
< TransactionIdentification> 000343717< / TransactionIdentification>
< ReleaseIdentification Type =" Original"
DateType =" Delivery"> 20011200< / ReleaseIdentification>
< DateTime> 2003-10-15T21:33:06.000Z< / DateTime>
< ; StartDateTime> 2003-10-13T21:33:06.000Z< / StartDateTime>
< EndDateTime> 2004-10-06T00:00:00.000Z< / EndDateTime>
- < ShipFrom>
- <公司>
等等....

这有什么帮助吗?

感谢您提供任何建议。

2003年10月20日星期一11:42:55 -0500,史蒂夫 < as*@abc.com>写道:

整个文档是什么样的?

要么在这里发布,要么给出我们可以看到的网址。

thx,

史蒂夫

" MeNotHome" < dtfa @ **** **** nospm&insightbb.com GT;在消息中写道
新闻:c7 ******************************** @ 4ax.com ..。< blockquote class =post_quotes>我正在自动导航网站。当我到达终点时,它会改变为xml。

所以我的axwebbrowser1里面有一堆xml数据。

所以这就是我想要的做什么

Dim xmlText As String
Dim doc As New XmlDocument()
Dim myElem As XmlElement
xmlText = AxWebBrowser1.Document.Body.OuterHTML
doc.LoadXml(xmlText)

但问题是我在
doc.loadxml(xmltext)上出现异常错误
我找到了一个streamreader示例,但我已经有了xml
axwebbrowser控件中的数据。

如何获取它以便我可以解析节点?

感谢您提供任何信息



I am automating the navigation of a website. When I reach the end, it
changes to xml.

So my axwebbrowser1 has a bunch of xml data in it.

So here is what I am trying to do

Dim xmlText As String
Dim doc As New XmlDocument()
Dim myElem As XmlElement
xmlText = AxWebBrowser1.Document.Body.OuterHTML
doc.LoadXml(xmlText)

But the problem is I get an exception error at the
doc.loadxml(xmltext)
I found a streamreader example but I already have the xml data in the
axwebbrowser control.

How do I get it so I can parse through the nodes?

Thanks for any information

解决方案

what does the entire document look like?

either post it here, or give the url so we can see.

thx,

steve
"MeNotHome" <dtfa@****nospm****insightbb.com> wrote in message
news:c7********************************@4ax.com...

I am automating the navigation of a website. When I reach the end, it
changes to xml.

So my axwebbrowser1 has a bunch of xml data in it.

So here is what I am trying to do

Dim xmlText As String
Dim doc As New XmlDocument()
Dim myElem As XmlElement
xmlText = AxWebBrowser1.Document.Body.OuterHTML
doc.LoadXml(xmlText)

But the problem is I get an exception error at the
doc.loadxml(xmltext)
I found a streamreader example but I already have the xml data in the
axwebbrowser control.

How do I get it so I can parse through the nodes?

Thanks for any information



I wish I could post the website but it''s on a password protected site.
But here is what the page looks like when viewed in ie6.

<?xml version="1.0" encoding="ISO-8859-1" ?>
- <ShipmentForecasts>
- <ShipmentForecast>
<extract-datetime
code="CST">2003-10-15T15:33:06.000-06:00</extract-datetime>
<FileKey>ALL1*23759*20011200*ALL1</FileKey>
<TransactionIdentification>000343717</TransactionIdentification>
<ReleaseIdentification Type="Original"
DateType="Delivery">20011200</ReleaseIdentification>
<DateTime>2003-10-15T21:33:06.000Z</DateTime>
<StartDateTime>2003-10-13T21:33:06.000Z</StartDateTime>
<EndDateTime>2004-10-06T00:00:00.000Z</EndDateTime>
- <ShipFrom>
- <Company>
etc etc....

Does this help at all?

Thanks for any advice you can give.

On Mon, 20 Oct 2003 11:42:55 -0500, "steve" <as*@abc.com> wrote:

what does the entire document look like?

either post it here, or give the url so we can see.

thx,

steve
"MeNotHome" <dtfa@****nospm****insightbb.com> wrote in message
news:c7********************************@4ax.com.. .

I am automating the navigation of a website. When I reach the end, it
changes to xml.

So my axwebbrowser1 has a bunch of xml data in it.

So here is what I am trying to do

Dim xmlText As String
Dim doc As New XmlDocument()
Dim myElem As XmlElement
xmlText = AxWebBrowser1.Document.Body.OuterHTML
doc.LoadXml(xmlText)

But the problem is I get an exception error at the
doc.loadxml(xmltext)
I found a streamreader example but I already have the xml data in the
axwebbrowser control.

How do I get it so I can parse through the nodes?

Thanks for any information




you know...that looks fine to me. i don''t see anything wrong with it. what
does the exception state?

here''s some "quicky code" that will help you parse xml in the meantime...i
didn''t have time to learn how the new xml stuff worked in .net so this was
my "5 minute problem solved" adaptation.

hth,

steve

Private Sub xmlParsing()
Dim xml As String
xml &= "<authorization>" & vbCrLf
xml &= " <record1>" & vbCrLf
xml &= " <id>1</id>" & vbCrLf
xml &= " <role>1</role>" & vbCrLf
xml &= " <description>system account</description>" & vbCrLf
xml &= " </record1>" & vbCrLf
xml &= " <record2>" & vbCrLf
xml &= " <id>2</id>" & vbCrLf
xml &= " <role>2</role>" & vbCrLf
xml &= " <description>administrator</description>" & vbCrLf
xml &= " </record2>" & vbCrLf
xml &= " <record3>" & vbCrLf
xml &= " <id>3</id>" & vbCrLf
xml &= " <role>3</role>" & vbCrLf
xml &= " <description>standard user</description>" & vbCrLf
xml &= " </record3>" & vbCrLf
xml &= "</authorization>" & vbCrLf
xml &= "<authorization>" & vbCrLf
xml &= " <record4>" & vbCrLf
xml &= " <id>4</id>" & vbCrLf
xml &= " <role>4</role>" & vbCrLf
xml &= " <description>system knob</description>" & vbCrLf
xml &= " </record4>" & vbCrLf
xml &= " <record5>" & vbCrLf
xml &= " <id>5</id>" & vbCrLf
xml &= " <role>5</role>" & vbCrLf
xml &= " <description>certified looser</description>" & vbCrLf
xml &= " </record5>" & vbCrLf
xml &= " <record6>" & vbCrLf
xml &= " <id>6</id>" & vbCrLf
xml &= " <role>6</role>" & vbCrLf
xml &= " <description>emmense whiner</description>" & vbCrLf
xml &= " </record6>" & vbCrLf
xml &= "</authorization>" & vbCrLf
Dim authorization() As String = getMultipleSegments("AUTHORIZATION", xml)
If authorization Is Nothing Then Return
Dim segment As String
For Each segment In authorization
Dim records() As String = getMultipleSegments("RECORD", segment)
If Not records Is Nothing Then
Dim description As String
Dim id As Integer
Dim record As String
Dim role As String
For Each record In records
id = CInt(getSegmentValue(getSingleSegment("ID", record), 0))
role = getSegmentValue(getSingleSegment("ROLE", record))
description = getSegmentValue(getSingleSegment("DESCRIPTION", record))
Console.WriteLine("id: " & id & ", role: " & role & ", description: " &
description)
Next
End If
Next
Console.ReadLine()
End Sub

Private Function getMultipleSegments(ByVal segment As String, ByVal xml As
String) As String()
If xml Is Nothing Then Exit Function
Dim pattern As String = "<\s*" & segment & "[^>]*>.*?<\s*/\s*" & segment &
"[^>]*?>"
Dim regExp As New Regex(pattern, RegexOptions.ExplicitCapture Or
RegexOptions.Singleline Or RegexOptions.IgnoreCase)
If Not regExp.IsMatch(xml) Then Exit Function
Dim match As Match
Dim result() As String
Dim index As Integer
For Each match In regExp.Matches(xml)
ReDim Preserve result(index)
result(index) = match.Value
index += 1
Next
Return result
End Function

Private Function getSingleSegment(ByVal segment As String, ByVal xml As
String) As String
If xml Is Nothing Then Exit Function
Dim pattern As String = "<\s*" & segment & "[^>]*>.*?<\s*/\s*" & segment &
"[^>]*?>"
Dim regExp As New Regex(pattern, RegexOptions.ExplicitCapture Or
RegexOptions.Singleline Or RegexOptions.IgnoreCase)
If Not regExp.IsMatch(xml) Then Exit Function
Dim match As Match = regExp.Match(xml)
Return match.Value
End Function

Private Overloads Function getSegmentValue(ByVal xml As String) As String
If xml Is Nothing Then Exit Function
Dim pattern As String = "<[^>]*>"
Dim regExp As New Regex(pattern)
If Not regExp.IsMatch(xml) Then Exit Function
Return regExp.Replace(xml, "")
End Function

Private Overloads Function getSegmentValue(ByVal xml As String, ByVal
emptyDefault As String) As String
Dim value As String = getSegmentValue(xml)
If value Is Nothing OrElse value.Trim = vbNullString Then value =
emptyDefault
Return value
End Function
"MeNotHome" <dtfa@****nospm****insightbb.com> wrote in message
news:6e********************************@4ax.com...

I wish I could post the website but it''s on a password protected site.
But here is what the page looks like when viewed in ie6.

<?xml version="1.0" encoding="ISO-8859-1" ?>
- <ShipmentForecasts>
- <ShipmentForecast>
<extract-datetime
code="CST">2003-10-15T15:33:06.000-06:00</extract-datetime>
<FileKey>ALL1*23759*20011200*ALL1</FileKey>
<TransactionIdentification>000343717</TransactionIdentification>
<ReleaseIdentification Type="Original"
DateType="Delivery">20011200</ReleaseIdentification>
<DateTime>2003-10-15T21:33:06.000Z</DateTime>
<StartDateTime>2003-10-13T21:33:06.000Z</StartDateTime>
<EndDateTime>2004-10-06T00:00:00.000Z</EndDateTime>
- <ShipFrom>
- <Company>
etc etc....

Does this help at all?

Thanks for any advice you can give.

On Mon, 20 Oct 2003 11:42:55 -0500, "steve" <as*@abc.com> wrote:

what does the entire document look like?

either post it here, or give the url so we can see.

thx,

steve
"MeNotHome" <dtfa@****nospm****insightbb.com> wrote in message
news:c7********************************@4ax.com.. .

I am automating the navigation of a website. When I reach the end, it
changes to xml.

So my axwebbrowser1 has a bunch of xml data in it.

So here is what I am trying to do

Dim xmlText As String
Dim doc As New XmlDocument()
Dim myElem As XmlElement
xmlText = AxWebBrowser1.Document.Body.OuterHTML
doc.LoadXml(xmlText)

But the problem is I get an exception error at the
doc.loadxml(xmltext)
I found a streamreader example but I already have the xml data in the
axwebbrowser control.

How do I get it so I can parse through the nodes?

Thanks for any information



这篇关于doc.loadxml(axwebbrowser1.document.body.outerhtml),不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆