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="">
Printable View
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="">
now lets say your xml doc looks like thisCode:Dim xmlDoc As MSXML.DOMDocument
Set xmlDoc = New MSXML.DOMDocument
xmlDoc.async = False
xmlDoc.load "c:\myxml.xml"
to get the ID attributeCode:<test>
<Cube ID="cls=clsCubeDataOptionChain;basecode=BVSN"/>
</test>
Code:Dim myid as string
myid = xmlDoc.selectSingleNode("test/Cube/@ID")
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
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?
Code:xmlDoc.selectSingleNode("test/Cube/@ID").text = "cls=clsCubeDataOptionChain;basecode=" & Text1.Text
xmlDoc.Save
Might I also make thisw suggestion. Change that Cube element to something like this if you can
Code:<Cube ID="" cls="clsCubeDataOptionChain" basecode="BVSN"/>