-
XML PARSER?
Could anyone help me out with SAX2 for vb?
say this is the xml file:
<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<s:Schema id="RowsetSchema">
<s:ElementType name="row" content="eltOnly" rs:CommandTimeout="30" rs:updatable="true"
rs:ReshapeName="DSRowset1_22">
<s:AttributeType name="KommInfo" rs:number="8" rs:nullable="true" rs:maydefer="true"
rs:writeunknown="true">
<s:datatype dt:type="int" dt:maxLength="4" rs recision="10" rs:fixedlength="true"
/>
</s:AttributeType>
</s:ElementType>
</s:Schema>
<rs:data>
</rs:data>
</xml>
and say I want to get the value "KommInfo" from name and,"8" from rs:number,
"4" from dt:maxLength
how should I do using SAX2 and MSXML 3.0? please help =(
-
Re: XML PARSER?
This should put you on the right track.
I yanked this code out and tried to line up your element names, but you will
have to tune it to get it to run.
Remember SAX reads top to bottom, once. But it's fast.
Best of luck,
Rick
First, set a reference to Microsoft XML, v3.0
Private Function parseDoc()
On Error GoTo ErrorHandler
Dim strURL As String
Dim reader As New SAXXMLReader
Dim SAXcontentHandler As New SaxMgr
strURL = gblDataPath & "\DownLoad\" & strTableName & ".xml"
Set gblDataBase = OpenDatabase(gblDataPath & "\" + strDataBase + ".mdb")
Set reader.contentHandler = SAXcontentHandler
gblTableName = strTableName
gblCustomerid = strCustomerid
'Parse the document
reader.parseURL (strURL)
CleanUp:
Set reader = Nothing
Exit Function
****SaxMgr class************************************************
Option Explicit
Private m_strFields As String
Private m_strValues As String
Implements IVBSAXContentHandler
Private Sub IVBSAXContentHandler_startElement(strNamespaceURI As String,
strLocalName As String, strQName As String, ByVal attributes As MSXML2.IVBSAXAttributes)
Dim i As Integer
Dim strName As String
Dim strNumber As String
Dim strmaxLength As String
Select Case strLocalName
Case "Schema"
Debug.Print "Found Schema element"
Case "AttributeType"
For i = 0 To (attributes.length - 1)
Select Case attributes.getLocalName(i)
Case "name" 'This is the name attribute
strName = attributes.getValue(i)
Case "number" 'This is the number attribute
strNumber = attributes.getValue(i)
End Select
Next
Case "datatype"
For i = 0 To (attributes.length - 1)
Select Case attributes.getLocalName(i)
Case "maxLength" 'This is the maxLength attribute
strmaxLength = attributes.getValue(i)
End Select
Next
End Select
And/Or, do your process here...
End Sub
Private Sub IVBSAXContentHandler_endElement(strNamespaceURI As String, strLocalName
As String, strQName As String)
'Declarations
Dim i As Integer
Dim strSQL As String
Select Case strLocalName
Case "AttributeType"
Debug.Print "End of element found"
'Do your process...
Case "maxLength"
Debug.Print "End of element found"
'Do your process...
End Select
End Sub
Private Sub IVBSAXContentHandler_characters(text As String)
'Debug.Print "Chars:" & text
End Sub
Private Property Set IVBSAXContentHandler_documentLocator(ByVal RHS As MSXML2.IVBSAXLocator)
End Property
Private Sub IVBSAXContentHandler_endDocument()
'Debug.Print "End Doc"
End Sub
Private Sub IVBSAXContentHandler_endPrefixMapping(strPrefix As String)
End Sub
Private Sub IVBSAXContentHandler_ignorableWhitespace(strChars As String)
End Sub
Private Sub IVBSAXContentHandler_processingInstruction(target As String,
data As String)
'Debug.Print "Instruction:"
End Sub
Private Sub IVBSAXContentHandler_skippedEntity(strName As String)
End Sub
Private Sub IVBSAXContentHandler_startDocument()
'Debug.Print "Start Doc"
End Sub
Private Sub IVBSAXContentHandler_startPrefixMapping(strPrefix As String,
strURI As String)
End Sub
ErrorHandler:
Set reader = Nothing
End Function
-
Re: XML PARSER?
THX Rick! (
but is it any way to automaticly get the name of the attributes? (schema,
name & number? just wondering because I want to make tables from the xml
file, and the xml file could contain more than one table, then I got to get
the root elements name, and the subelements name, is it possible? =/
>Private Sub IVBSAXContentHandler_startElement(strNamespaceURI As String,
>strLocalName As String, strQName As String, ByVal attributes As MSXML2.IVBSAXAttributes)
>
> Dim i As Integer
> Dim strName As String
> Dim strNumber As String
> Dim strmaxLength As String
>
> Select Case strLocalName
> Case "Schema"
> Debug.Print "Found Schema element"
>
> Case "AttributeType"
> For i = 0 To (attributes.length - 1)
> Select Case attributes.getLocalName(i)
> Case "name" 'This is the name attribute
> strName = attributes.getValue(i)
> Case "number" 'This is the number attribute
> strNumber = attributes.getValue(i)
> End Select
> Next
>
> Case "datatype"
> For i = 0 To (attributes.length - 1)
> Select Case attributes.getLocalName(i)
> Case "maxLength" 'This is the maxLength attribute
> strmaxLength = attributes.getValue(i)
> End Select
> Next
>
> End Select
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|