Results 1 to 6 of 6

Thread: Question on XML DOM object

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2001
    Location
    Chicago
    Posts
    11

    Question on XML DOM object

    Does anyone know how I can parse the strings in the quote marks from the following code in XML?

    <Cube ID="cls=clsCubeDataOptionChain;basecode=BVSN"/>
    <Section ID="" Filters="">
    I'm a summer intern with a hefty assignment!!!

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Code:
    Dim xmlDoc As MSXML.DOMDocument
    Set xmlDoc = New MSXML.DOMDocument
    xmlDoc.async = False
    xmlDoc.load "c:\myxml.xml"
    now lets say your xml doc looks like this
    Code:
    <test>
      <Cube ID="cls=clsCubeDataOptionChain;basecode=BVSN"/> 
    </test>
    to get the ID attribute

    Code:
    Dim myid as string
    myid = xmlDoc.selectSingleNode("test/Cube/@ID")
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810

    Thumbs up OR............

    Code:
    Dim oXMLdoc     As MSXML2.DOMDocument
    Dim oElement    As MSXML2.IXMLDOMElement
    Dim oAttrib     As MSXML2.IXMLDOMAttribute
    Dim strXML      As String
    Dim strData     As String
    Dim sSplit()    As String
    
    Set oXMLdoc = New MSXML2.DOMDocument
    strXML = "<Data><Cube ID='cls=clsCubeDataOptionChain;basecode=BVSN'/>" & _
             "<Section ID='' Filters=''/></Data>"
          
    oXMLdoc.loadXML strXML
    
    
    Set oElement = oXMLdoc.selectSingleNode("Data/Cube")
    
    If Not oElement.Attributes Is Nothing Then
        For Each oAttrib In oElement.Attributes
            If oAttrib.Name = "ID" Then
                strData = oAttrib.Text
                sSplit = Split(strData, ";")
                If InStr(1, sSplit(0), "cls") Then
                    Debug.Print Mid(sSplit(0), 5)
                End If
                If InStr(1, sSplit(1), "basecode") Then
                    Debug.Print Mid(sSplit(1), 10)
                End If
            End If
        Next oAttrib
    End If
    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2001
    Location
    Chicago
    Posts
    11

    Thanks guys

    I was able to use your guidance. It worked great. Now, the only thing I'm still trying to figure out is how to edit the text of an attribute.

    For instance:

    <ft>
    <Cube ID="cls=clsCubeDataOptionChain;basecode=BVSN"/>

    Say I wanted to get the text from a text box and change "BVSN" to the new text from the user. Which XML method does this the best?
    I'm a summer intern with a hefty assignment!!!

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Code:
    xmlDoc.selectSingleNode("test/Cube/@ID").text = "cls=clsCubeDataOptionChain;basecode=" & Text1.Text
    xmlDoc.Save
    Last edited by Cander; Jun 15th, 2001 at 01:54 PM.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Might I also make thisw suggestion. Change that Cube element to something like this if you can

    Code:
    <Cube ID="" cls="clsCubeDataOptionChain" basecode="BVSN"/>
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width