예를 들어, VBA, 구문 분석 문자열으로 내가 작업하십시오 원합니다.
<PointN xsi:type='typens:PointN'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xs='http://www.w3.org/2001/XMLSchema'>
<X>24.365</X>
<Y>78.63</Y>
</PointN>
x 의 성능을 높이고 &. 분리된 두 개의 정수 값을 y 로 com/go/4e6b330a_kr.
어떻게 해야 합니까?
포인터는 주셔서 감사합니다.
내가 이 문제를 해결하기 위한 가장 좋은 표시할지를 don& # 39, t know, I got it is how 외곽진입 방관하겠나 하지만, 여기에 있는 것이다. 내가 referenced Microsoft XML, VBA, 다음 날, 내 다음 코드와 v2.6 dll 을 통해 필요한 값을
<! - 모든 언어: > vb 랭 -;
Dim objXML As MSXML2.DOMDocument
Set objXML = New MSXML2.DOMDocument
If Not objXML.loadXML(strXML) Then 'strXML is the string with XML'
Err.Raise objXML.parseError.ErrorCode, , objXML.parseError.reason
End If
Dim point As IXMLDOMNode
Set point = objXML.firstChild
Debug.Print point.selectSingleNode("X").Text
Debug.Print point.selectSingleNode("Y").Text
이는 복잡한 질문 것 같은데 조금 있지만, 가장 직접적인 라우트를 약간만이라도 읽어들입니다 MSXML2.DOMDocument 통해 XML 문서 또는 XML 문자열이 있습니다 그러면 xlm 액세스하려면 노드입니다.
보다 자세한 내용은 다음 사이트에 MSXML2.DOMDocument 찾을 수 있습니다.
[1]: //en.allexperts.com/q/xml-1469/manipulating-xml-files-excel.htm https://web.archive.org/web/20161217090033/http [2]: //www.xml.com:80/lpt/a/979 https://web.archive.org/web/20161030020427/http
Xpath 쿼리하지 사용할 수 있습니다.
<! - 모든 언어: > vb 랭 -;
Dim objDom As Object '// DOMDocument
Dim xmlStr As String, _
xPath As String
xmlStr = _
"<PointN xsi:type='typens:PointN' " & _
"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " & _
"xmlns:xs='http://www.w3.org/2001/XMLSchema'> " & _
" <X>24.365</X> " & _
" <Y>78.63</Y> " & _
"</PointN>"
Set objDom = CreateObject("Msxml2.DOMDocument.3.0") '// Using MSXML 3.0
'/* Load XML */
objDom.LoadXML xmlStr
'/*
' * XPath Query
' */
'/* Get X */
xPath = "/PointN/X"
Debug.Print objDom.SelectSingleNode(xPath).text
'/* Get Y */
xPath = "/PointN/Y"
Debug.Print objDom.SelectSingleNode(xPath).text
Microsoft XML 예제 코드 참조 추가, 참조입니다 Project->, 6.0 및 사용할 수 있습니다.
<! - 모든 언어: > vb 랭 -;
Dim xml As String
xml = "<root><person><name>Me </name> </person> <person> <name>No Name </name></person></root> "
Dim oXml As MSXML2.DOMDocument60
Set oXml = New MSXML2.DOMDocument60
oXml.loadXML xml
Dim oSeqNodes, oSeqNode As IXMLDOMNode
Set oSeqNodes = oXml.selectNodes("//root/person")
If oSeqNodes.length = 0 Then
'show some message
Else
For Each oSeqNode In oSeqNodes
Debug.Print oSeqNode.selectSingleNode("name").Text
Next
End If
xml 노드를 루트 / / / / / 비 케어플 위드 스크립트루트 / 사람, 또 한 사람이 아니라 함께 같은 셀레스싱글노데 (Name" ";) 와 동일한 셀레스싱글노데 .text .text 아니다 (name" ";)
이 예는 OPML 파서 작업 파일을 FeedDemon opml:
<! - 모든 언어: > vb 랭 -;
Sub debugPrintOPML()
' http://msdn.microsoft.com/en-us/library/ms763720(v=VS.85).aspx
' http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.selectnodes.aspx
' http://msdn.microsoft.com/en-us/library/ms256086(v=VS.85).aspx ' expressions
' References: Microsoft XML
Dim xmldoc As New DOMDocument60
Dim oNodeList As IXMLDOMSelection
Dim oNodeList2 As IXMLDOMSelection
Dim curNode As IXMLDOMNode
Dim n As Long, n2 As Long, x As Long
Dim strXPathQuery As String
Dim attrLength As Byte
Dim FilePath As String
FilePath = "rss.opml"
xmldoc.Load CurrentProject.Path & "\" & FilePath
strXPathQuery = "opml/body/outline"
Set oNodeList = xmldoc.selectNodes(strXPathQuery)
For n = 0 To (oNodeList.length - 1)
Set curNode = oNodeList.Item(n)
attrLength = curNode.Attributes.length
If attrLength > 1 Then ' or 2 or 3
Call processNode(curNode)
Else
Call processNode(curNode)
strXPathQuery = "opml/body/outline[position() = " & n + 1 & "]/outline"
Set oNodeList2 = xmldoc.selectNodes(strXPathQuery)
For n2 = 0 To (oNodeList2.length - 1)
Set curNode = oNodeList2.Item(n2)
Call processNode(curNode)
Next
End If
Debug.Print "----------------------"
Next
Set xmldoc = Nothing
End Sub
Sub processNode(curNode As IXMLDOMNode)
Dim sAttrName As String
Dim sAttrValue As String
Dim attrLength As Byte
Dim x As Long
attrLength = curNode.Attributes.length
For x = 0 To (attrLength - 1)
sAttrName = curNode.Attributes.Item(x).nodeName
sAttrValue = curNode.Attributes.Item(x).nodeValue
Debug.Print sAttrName & " = " & sAttrValue
Next
Debug.Print "-----------"
End Sub
이 폴더 진단트리를 우선적으로 레벨 (아와스, 뉴스테롤라):
...
Call xmldocOpen4
Call debugPrintOPML4(Null)
...
Dim sText4 As String
Sub debugPrintOPML4(strXPathQuery As Variant)
Dim xmldoc4 As New DOMDocument60
'Dim xmldoc4 As New MSXML2.DOMDocument60 ' ?
Dim oNodeList As IXMLDOMSelection
Dim curNode As IXMLDOMNode
Dim n4 As Long
If IsNull(strXPathQuery) Then strXPathQuery = "opml/body/outline"
' http://msdn.microsoft.com/en-us/library/ms754585(v=VS.85).aspx
xmldoc4.async = False
xmldoc4.loadXML sText4
If (xmldoc4.parseError.errorCode <> 0) Then
Dim myErr
Set myErr = xmldoc4.parseError
MsgBox ("You have error " & myErr.reason)
Else
' MsgBox xmldoc4.xml
End If
Set oNodeList = xmldoc4.selectNodes(strXPathQuery)
For n4 = 0 To (oNodeList.length - 1)
Set curNode = oNodeList.Item(n4)
Call processNode4(strXPathQuery, curNode, n4)
Next
Set xmldoc4 = Nothing
End Sub
Sub processNode4(strXPathQuery As Variant, curNode As IXMLDOMNode, n4 As Long)
Dim sAttrName As String
Dim sAttrValue As String
Dim x As Long
For x = 0 To (curNode.Attributes.length - 1)
sAttrName = curNode.Attributes.Item(x).nodeName
sAttrValue = curNode.Attributes.Item(x).nodeValue
'If sAttrName = "text"
Debug.Print strXPathQuery & " :: " & sAttrName & " = " & sAttrValue
'End If
Next
Debug.Print ""
If curNode.childNodes.length > 0 Then
Call debugPrintOPML4(strXPathQuery & "[position() = " & n4 + 1 & "]/" & curNode.nodeName)
End If
End Sub
Sub xmldocOpen4()
Dim oFSO As New FileSystemObject ' Microsoft Scripting Runtime Reference
Dim oFS
Dim FilePath As String
FilePath = "rss_awasu.opml"
Set oFS = oFSO.OpenTextFile(CurrentProject.Path & "\" & FilePath)
sText4 = oFS.ReadAll
oFS.Close
End Sub
이상의:
Sub xmldocOpen4()
Dim FilePath As String
FilePath = "rss.opml"
' function ConvertUTF8File(sUTF8File):
' http://www.vbmonster.com/Uwe/Forum.aspx/vb/24947/How-to-read-UTF-8-chars-using-VBA
' loading and conversion from Utf-8 to UTF
sText8 = ConvertUTF8File(CurrentProject.Path & "\" & FilePath)
End Sub
근데 난 왜 매번 don& # 39, 이해하지 xmldoc4 로드할지.
아래에 제시된 절차를 통해 XML DOM 객체에는 VBA 를 사용하여 XML 파싱 보기입니다 예입니다. 코드 기반으로 하는 초보자 가이드를 XML DOM.
<! - 모든 언어: > vb 랭 -;
Public Sub LoadDocument()
Dim xDoc As MSXML.DOMDocument
Set xDoc = New MSXML.DOMDocument
xDoc.validateOnParse = False
If xDoc.Load("C:\My Documents\sample.xml") Then
' The document loaded successfully.
' Now do something intersting.
DisplayNode xDoc.childNodes, 0
Else
' The document failed to load.
' See the previous listing for error information.
End If
End Sub
Public Sub DisplayNode(ByRef Nodes As MSXML.IXMLDOMNodeList, _
ByVal Indent As Integer)
Dim xNode As MSXML.IXMLDOMNode
Indent = Indent + 2
For Each xNode In Nodes
If xNode.nodeType = NODE_TEXT Then
Debug.Print Space$(Indent) & xNode.parentNode.nodeName & _
":" & xNode.nodeValue
End If
If xNode.hasChildNodes Then
DisplayNode xNode.childNodes, Indent
End If
Next xNode
End Sub
>. - 노타 베네 이 초기 오토메이티드 fs@snapa 한가지는 짐작할 수 있을 수 있는 가장 간단한 (당시 매우 구체적인 문제에 대한 작업을 난). >. Vba 를 사용하여 XML Dom 약간만이라도 내장되었을 xlm 협업공간을 자연스럽게 >. 내가 긁어줄게. 지켜보리니 업데이트 한다.
하지만 난 내 단순한 솔루션 그러니까말이야 이는 매우 오래된 게시물로의 나누고 싶었던 이 복잡한 질문이예요 # 39, ve I& 주로 사용되는 기본 문자열 함수 xml 데이터를 액세스하려면.
이 경우 가정 내에 있는 일부 xml 데이터 (임시 변수) 가 반환되었는지 VBA 로 시작된다. 나는 한 가지 흥미로운 점은 충분한 가치를 어떻게 링크하려는 읽어들이려면 xml 웹 서비스를 볼 수도 있습니다. 또한 이 Excel VBA 는 값을 조회 기능 때문에 이미지에 표시된 함수를 사용하여 세포 내에서 https://learning. 펑크티온임 (value1, value2) 를 통해 웹 서비스 = 반환 값 붙여넣습니다 스프레드시트입니다.
< pre> < code>;;; 오픈택 = " < ";; &. 태그바루이 &. " > ";; 클로스택 = " <; /". &. 태그바루이 &. " > ";; & # 39 br> <;; 위치를 닫기 태그가 있다 스타르포스 = 린스트 (1, 온도, 오픈택) 에드포스 = 린스트 (1, 온도, 클로스택) 스타르타히포스 = 린스트 (스타르포스, 온도, " " >;;) + 1 & # 39. Xml 의 값을 반환되었습니다 구문 분석 데이터 = 미드플레인 (온도, 스타르타히포스, 에드포스 - 스타르타히포스) < /pre> < /code>;;;
이것은 데이터를 분석할 수 있는 XML 파일 확장자입니다 파선-짧은 서브노드 MicroStation 트리포르마 구조용 강철 날까로움.
<! - 모든 언어: > vb 랭 -;
'location of triforma structural files
'c:\programdata\bentley\workspace\triforma\tf_imperial\data\us.xml
Sub ReadTriformaImperialData()
Dim txtFileName As String
Dim txtFileLine As String
Dim txtFileNumber As Long
Dim Shape As String
Shape = "w12x40"
txtFileNumber = FreeFile
txtFileName = "c:\programdata\bentley\workspace\triforma\tf_imperial\data\us.xml"
Open txtFileName For Input As #txtFileNumber
Do While Not EOF(txtFileNumber)
Line Input #txtFileNumber, txtFileLine
If InStr(1, UCase(txtFileLine), UCase(Shape)) Then
P1 = InStr(1, UCase(txtFileLine), "D=")
D = Val(Mid(txtFileLine, P1 + 3))
P2 = InStr(1, UCase(txtFileLine), "TW=")
TW = Val(Mid(txtFileLine, P2 + 4))
P3 = InStr(1, UCase(txtFileLine), "WIDTH=")
W = Val(Mid(txtFileLine, P3 + 7))
P4 = InStr(1, UCase(txtFileLine), "TF=")
TF = Val(Mid(txtFileLine, P4 + 4))
Close txtFileNumber
Exit Do
End If
Loop
End Sub
여기에서 모양을 그릴 수 있는 값을 사용할 수 있습니다 MicroStation 2d 또는 3d 로 do it 및 extrude redhat. 솔리드입니다.
Cell A1: {your XML here}
Cell B1: <X>
Cell C1: </X>
Cell D1: =REPLACE(A1,1,FIND(A2,A1)+LEN(A2)-1,"")
Cell E1: =REPLACE(A4,FIND(A3,A4),LEN(A4)-FIND(A3,A4)+1,"")
그 결과 값을 갖게 될 줄 E1 너회의 분석되었다.
Cell A1: {your XML here}
Cell B1: <X>
Cell C1: </X>
Cell D1: 24.365<X><Y>78.68</Y></PointN>
Cell E1: 24.365