XML Newbie Needs Help With Parsing 
Author Message
 XML Newbie Needs Help With Parsing

I'm posting this not having done the good 'ol RTFM thing....mostly because I
couldn't find the "M" anywhere in a timely fashion.  Forgive my ignorance,
but I hope someone will be so good as to point me in the right direction.

Consider the following text in a standard HTML document:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns=" http://www.*-*-*.com/ ; xmlns:o =
"urn:schemas-microsoft-com:office:office" xmlns:x =
"urn:schemas-microsoft-com:office:excel"><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content=Excel.Sheet name=ProgId>
<META content="MSHTML 5.50.4207.2601" name=GENERATOR><LINK
href="./ExcelOutput_files/filelist.xml" rel=File-List>
<STYLE id=Book2_19310_Styles>TABLE {
 mso-displayed-decimal-separator: "\."; mso-displayed-thousand-separator:
"\,"

Quote:
}

.xl1519310 {
 PADDING-RIGHT: 1px; PADDING-LEFT: 1px; FONT-WEIGHT: 400; FONT-SIZE: 10pt;
VERTICAL-ALIGN: bottom; COLOR: windowtext; PADDING-TOP: 1px; FONT-STYLE:
normal; FONT-FAMILY: Arial; WHITE-SPACE: nowrap; TEXT-DECORATION: none;
mso-ignore: padding; mso-generic-font-family: auto; mso-font-charset: 0;
mso-number-format: General; mso-background-source: auto; mso-pattern: auto

Quote:
}

I've omitted the remaining style defs here.  Suffice it to say there are
several prefexed as ".xl...".  And, yes yes...it's from MS Excel.  But
further down in the document is some data I'd like parsed out to use in my
application.  To do that I've been trying to apply the
getElementsByTagName() method of the XMLDocument object from within VB.
(This object is contained in MSXML.DLL and cited in the project references
list as "Microsoft XML, version 2.0".)  The tag I'm seeking is contained in
this same HTML document as follows:

...
<TD class=xl5219310 style="WIDTH: 53pt" width=70 u1:num x:num>63.000</TD>
...

Then I created a simple standard.exe VB 6.0 project to take all the elements
specified in a textbox called txtID and displaythem in a listbox called
lstIDs.  The code I used follows:

=====

Option Explicit

Public xmlDOc 'As Object

Private Sub cmdGetIDs_Click()

Dim objNodeList As Object
Dim i As Integer

Set objNodeList = xmlDOc.getElementsByTagName(txtID)

MsgBox "Break!", vbOKOnly

For i = 0 To (objNodeList.length - 1)
    MsgBox "Entered loop!", vbOKOnly
    lstIDs.AddItem objNodeList.Item(i).Text
Next

End Sub

Private Sub cmdGo_Click()

Set xmlDOc = CreateObject("Microsoft.xmldom")
xmlDOc.async = False

If txtURL <> "" Then
    xmlDOc.Load (txtURL)
End If

End Sub

=====

This code is basically out of the samples from the MSDN library, but I can't
get anything to display in the listbox, much less even verify that my XML
document (which is actually an HTML document) is loading.  When I queried
the Immediate window after loading running the application to return the
length of objNodeList (i.e. "?objNodeList.length"), all I ever got was 0.

Can anyone tell me what I'm doing wrong?  What I'm doing right?

Gratefully,

--

Web Developer, Cognos Inc.
http://www.*-*-*.com/



Tue, 25 Mar 2003 03:00:00 GMT  
 XML Newbie Needs Help With Parsing


Quote:

> I'm posting this not having done the good 'ol RTFM thing....mostly
because I
> couldn't find the "M" anywhere in a timely fashion.  Forgive my
ignorance,
> but I hope someone will be so good as to point me in the right
direction.

> Consider the following text in a standard HTML document:

hello
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:o =
> "urn:schemas-microsoft-com:office:office" xmlns:x =
> "urn:schemas-microsoft-com:office:excel"><HEAD>
> <META http-equiv=Content-Type content="text/html; charset=windows-
1252">
> <META content=Excel.Sheet name=ProgId>
> <META content="MSHTML 5.50.4207.2601" name=GENERATOR><LINK
> href="./ExcelOutput_files/filelist.xml" rel=File-List>
> <STYLE id=Book2_19310_Styles>TABLE {
>  mso-displayed-decimal-separator: "\."; mso-displayed-thousand-
separator:
> "\,"
> }
> .xl1519310 {
>  PADDING-RIGHT: 1px; PADDING-LEFT: 1px; FONT-WEIGHT: 400; FONT-SIZE:
10pt;
> VERTICAL-ALIGN: bottom; COLOR: windowtext; PADDING-TOP: 1px; FONT-
STYLE:
> normal; FONT-FAMILY: Arial; WHITE-SPACE: nowrap; TEXT-DECORATION:
none;
> mso-ignore: padding; mso-generic-font-family: auto; mso-font-charset:
0;
> mso-number-format: General; mso-background-source: auto; mso-pattern:
auto
> }

> I've omitted the remaining style defs here.  Suffice it to say there
are
> several prefexed as ".xl...".  And, yes yes...it's from MS Excel.  But
> further down in the document is some data I'd like parsed out to use
in my
> application.  To do that I've been trying to apply the
> getElementsByTagName() method of the XMLDocument object from within
VB.
> (This object is contained in MSXML.DLL and cited in the project
references
> list as "Microsoft XML, version 2.0".)  The tag I'm seeking is
contained in
> this same HTML document as follows:

> ...
> <TD class=xl5219310 style="WIDTH: 53pt" width=70 u1:num
x:num>63.000</TD>
> ...

> Then I created a simple standard.exe VB 6.0 project to take all the
elements
> specified in a textbox called txtID and displaythem in a listbox
called
> lstIDs.  The code I used follows:

> =====

> Option Explicit

> Public xmlDOc 'As Object

> Private Sub cmdGetIDs_Click()

> Dim objNodeList As Object
> Dim i As Integer

> Set objNodeList = xmlDOc.getElementsByTagName(txtID)

> MsgBox "Break!", vbOKOnly

> For i = 0 To (objNodeList.length - 1)
>     MsgBox "Entered loop!", vbOKOnly
>     lstIDs.AddItem objNodeList.Item(i).Text
> Next

> End Sub

> Private Sub cmdGo_Click()

> Set xmlDOc = CreateObject("Microsoft.xmldom")
> xmlDOc.async = False

> If txtURL <> "" Then
>     xmlDOc.Load (txtURL)
> End If

> End Sub

> =====

> This code is basically out of the samples from the MSDN library, but
I can't
> get anything to display in the listbox, much less even verify that my
XML
> document (which is actually an HTML document) is loading.  When I
queried
> the Immediate window after loading running the application to return
the
> length of objNodeList (i.e. "?objNodeList.length"), all I ever got
was 0.

> Can anyone tell me what I'm doing wrong?  What I'm doing right?

> Gratefully,

> --

> Web Developer, Cognos Inc.
> http://www.cognos.com

> hello Ross Holder

why you use all the time with the object
i dont no if its the problem

and here some code for GetElementByTagName:

Dim Odoc as Msxml.DomDocument
Dim oTablelist as Msxml.IXMLDOMNODELIST
Dim oElement as msxml.IXMLDOMElement
set oDoc = new domDocument

sFileName=app.path & "YOUR_FILE.htm"
oDoc.async=false
b=odoc.load(sFileName)
if b=false then _
   exit sub

set oTableList=oDoc.GetElementByTAgNAme("Element Name")
msgbox oTableList.length
for i=0 to oTablelist.length-1
    msgbox oTableList.item(i).text
next

Sent via Deja.com http://www.deja.com/
Before you buy.



Tue, 25 Mar 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. vb.net newbie needs help with basic XML parsing

2. HELP - I need to parse xml with vbscript

3. newbie needs help parsing csv file

4. Newbie needs help parsing strings

5. Parsing XML from an ASP page that Creates XML fails

6. XML Newbie question, getting a value from an XML string

7. XML Parse

8. How to parse XML from a VBA macro

9. Starting external application from Word/Parsing XML

10. XML parsing in .net

11. how to parse wml (xml) files

12. XML Parse

 

 
Powered by phpBB® Forum Software