This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Microsoft XML > June 2006 > Generic XML Parser?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Generic XML Parser?
|
|
| (PeteCresswell) 2006-06-27, 8:28 pm |
| Are there widely-used/debugged routines that will parse any XML file?
Right now, as a total noob, I'm explicitly parsing out what I want.
e.g.
============================================================
4060 Set myNL = myXmlDoc.selectNodes("//SECURITY")
4070 For Each myNode In myNL
4071 curInputKey = myNode.selectSingleNode("NAME").Text
4072 curCusip = myNode.selectSingleNode("ID_CUSIP").Text
4074 curSecurityName = myNode.selectSingleNode("NAME").Text
4075 curCusipReal = myNode.selectSingleNode("ID_CUSIP_REAL").Text
4079 curSector = myNode.selectSingleNode("INDUSTRY_SECTOR").Text
4080 curSectorNumber = myNode.selectSingleNode("INDUSTRY_SECTOR_NUM").Text
4081 curSubgroup = myNode.selectSingleNode("INDUSTRY_SUBGROUP").Text
4082 curSubgroupNumber =
myNode.selectSingleNode("INDUSTRY_SUBGROUP_NUM").Text
4299 Next myNode
================================================================
Seems like that code is going to be needlessly maintenance-intensive if/when we
want to add new data fields.
Since we're sending the web service a list of data fields we want, it seems like
the code should just iterate through the XML once to figure out how many field
names there are, what the hierarchy is, and which fields repeat... and then go
through it again to pick off everything there is to pick....
--
PeteCresswell
| |
| Peter Flynn 2006-06-27, 8:28 pm |
| (PeteCresswell) wrote:
> Are there widely-used/debugged routines that will parse any XML file?
Thousands, possibly 10s of thousands. Every CS student on the pklanet
probably has to write an XML parser at some stage. How many are bug-free
I can't say :-) Any XML parser should parse any XML document, otherwise
it's worthless.
Searching Google for "xml parser" shows 9M results.
///Peter
| |
| Gadrin@gmail.com 2006-06-27, 8:28 pm |
|
Peter Flynn wrote:[color=darkred]
> (PeteCresswell) wrote:
I think you want to look into something that'll process the .childNodes
collection.
Basically, you can start at the root (documentElement) and then process
it's children one by one, and the children of those, etc, etc.
If you build some recursive functions you should be able to pass it a
node reference and it'll loop thru it's children. Then you inspect the
..childNodes property of each of those nodes. If it has children, then
you call the subroutine again.
So, the answer is ultimately "yes" -- you can process an XML document
without explicitly knowing it's element names.
You'll need to make further allowances for attributes collections and
mixing of both.
Example
The following Microsoft=AE Visual Basic=AE example uses the childNodes
property (collection) to return an IXMLDOMNodeList, and then iterates
through the collection, displaying the value of each item's xml
property.
Dim xmlDoc As New Msxml2.DOMDocument40
Dim root As IXMLDOMElement
Dim oNodeList As IXMLDOMNodeList
Dim Item As IXMLDOMNode
xmlDoc.async =3D False
xmlDoc.Load ("books.xml")
If (xmlDoc.parseError.errorCode <> 0) Then
Dim myErr
Set myErr =3D xmlDoc.parseError
MsgBox("You have error " & myErr.reason)
Else
Set root =3D xmlDoc.documentElement
Set oNodeList =3D root.childNodes
For Each Item In oNodeList
MsgBox Item.xml
Next
End If
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|