217 lines
5.1 KiB
Plaintext
217 lines
5.1 KiB
Plaintext
<%
|
|
Class XMLClass
|
|
Private m_DOM,nodeRoot,nodeItem,nodeMessage,nodeError,nodeAct,nodeActRet
|
|
|
|
'생성자
|
|
Private Sub Class_Initialize
|
|
Set m_DOM = Server.CreateObject("Microsoft.XMLDOM")
|
|
m_DOM.async=true'"false"
|
|
End Sub
|
|
|
|
'소멸자
|
|
Private Sub Class_Terminate
|
|
Set m_DOM = Nothing
|
|
End Sub
|
|
|
|
'노드 갯수 알아내기
|
|
Public Property Get NodeCount()
|
|
Dim objRoot
|
|
If m_DOM.ParseError.ErrorCode=0 Then
|
|
Set objRoot = m_DOM.documentElement
|
|
NodeCount = objRoot.childNodes.Length
|
|
Else
|
|
NodeCount = -1
|
|
End IF
|
|
End Property
|
|
|
|
'해당 태그 값 가져오기 중복인 경우 Index 기준으로 가져옴
|
|
Public Property Get TagText(tagName,index)
|
|
Dim Nodes
|
|
|
|
If m_DOM.ParseError.ErrorCode=0 Then
|
|
Set Nodes = m_DOM.getElementsByTagName(tagName)
|
|
If VarType(Nodes)<>0 And VarType(Nodes)<>1 Then
|
|
If Nodes.Length>0 Then
|
|
TagText = Nodes(index).Text
|
|
Else
|
|
TagText = ""
|
|
End IF
|
|
Else
|
|
TagText = ""
|
|
End IF
|
|
Set Nodes = Nothing
|
|
Else
|
|
TagText = null
|
|
End IF
|
|
End Property
|
|
|
|
'해당 태그의 제일 처음 값을 가져옴
|
|
Public Property Get TagValue(tagName)
|
|
Dim tv
|
|
tv = TagText(tagName,0)
|
|
TagValue = Replace(Replace(tv,"<![CDATA[",""),"]]>","")
|
|
End Property
|
|
|
|
'해당 노드를 가져옴
|
|
Public Property Get Nodes(tagName)
|
|
Set Nodes = m_DOM.getElemnetsByTagName(tagName)
|
|
End Property
|
|
|
|
'노드에 값 변경하기
|
|
'중복된 TAG가 있는 경우 첫번째 값만 변한다
|
|
Public Sub SetValue(tagName,tagValue)
|
|
Dim tValue
|
|
|
|
If InStr(tagValue,">")>0 Or InStr(tagValue,"<")>0 Then
|
|
tValue = ConvertHTML(tagValue)
|
|
Else
|
|
tValue = tagValue
|
|
End IF
|
|
|
|
With m_DOM
|
|
Set nodeRoot = .DocumentElement
|
|
Set nodeItem = .getElementsByTagName(tagName)
|
|
|
|
If VarType(nodeItem)<>0 And VarType(nodeItem)<>1 And nodeItem.Length<>0 Then
|
|
nodeItem(0).Text = tValue
|
|
Else
|
|
Set nodeItem = nodeRoot.AppendChild(.CreateElement(tagName))
|
|
nodeItem.Text = tValue
|
|
End If
|
|
End With
|
|
|
|
End Sub
|
|
|
|
'다른 서버의 XML 파일을 읽어옴
|
|
Public Function LoadHTTP(url)
|
|
With m_DOM
|
|
.async = False
|
|
.setProperty "ServerHTTPRequest",True
|
|
LoadHTTP = .Load(url)
|
|
End With
|
|
End Function
|
|
|
|
'현재 서버의 XML 파일을 읽어옴
|
|
Public Function Load(file)
|
|
Load = LoadHDD(Server.MapPath(file))
|
|
End Function
|
|
|
|
'현재 서버의 XML 파일을 읽어옴
|
|
Public Function LoadHDD(file)
|
|
With m_DOM
|
|
.async = False
|
|
LoadHDD = .Load(file)
|
|
End With
|
|
End Function
|
|
|
|
'현재 서버에 해당 XML 파일을 저장
|
|
Public Function Save(file)
|
|
SaveHDD Server.MapPath(file)
|
|
End Function
|
|
|
|
Public Function SaveHDD(file)
|
|
With m_DOM
|
|
.async = False
|
|
.Save file
|
|
End With
|
|
End Function
|
|
|
|
'Tag가 들어가는 HTML 내용을 추가하는 경우
|
|
'변환해서 XML에 오류를 없애주는 경우
|
|
Private Function ConvertHTML(strTxt)
|
|
ConvertHTML = "<![CDATA[" & strTxt & "]]>"
|
|
End Function
|
|
|
|
'// 받은 쿼리 데이터를 XML 형식으로 변환
|
|
Public Function XmlQuery(Ar,Field)
|
|
Dim nodeTitle,nodeName,nodeValue
|
|
Dim key,title,value
|
|
Dim i,x
|
|
|
|
With m_DOM
|
|
|
|
.async = False
|
|
.appendChild(.createProcessingInstruction("xml","version=""1.0"" encoding=""utf-8"" "))
|
|
|
|
' 루트 생성
|
|
Set nodeRoot = .CreateElement("ITEMS")
|
|
.appendChild(nodeRoot)
|
|
|
|
If IsArray(Ar) Then
|
|
For i = 0 To UBound(Ar,2)
|
|
Set nodeItem = nodeRoot.AppendChild(.CreateElement("ITEM"))
|
|
|
|
x = 0
|
|
For Each key In Split(Field,",")
|
|
Set nodeName = nodeItem.AppendChild(.CreateElement(key))
|
|
|
|
value = Ar(x,i)
|
|
If Not IsNull(value) Then
|
|
nodeName.Text = .createCDATASection(value).text
|
|
End If
|
|
x = x + 1
|
|
Next
|
|
Next
|
|
End If
|
|
|
|
End With
|
|
|
|
End Function
|
|
|
|
'빈 XML 파일 만들기
|
|
Public Function CreateXML(Ar)
|
|
Dim nTitle,nName
|
|
Dim datas,iCnt,xCnt
|
|
Dim key
|
|
|
|
With m_DOM
|
|
.async = False
|
|
.appendChild(.createProcessingInstruction("xml","version=""1.0"" encoding=""utf-8"" "))
|
|
|
|
Set nodeRoot = .CreateElement("ITEMS")
|
|
.appendChild(nodeRoot)
|
|
|
|
If IsArray(Ar) Then
|
|
For iCnt=0 To UBound(Ar)
|
|
If VarType(Ar(iCnt))<>0 And VarType(Ar(iCnt))<>1 Then
|
|
Set NodeItem = nodeRoot.AppendChild(.CreateElement(Ar(iCnt)))
|
|
End IF
|
|
Next
|
|
Else
|
|
For Each key In Split(Ar,",")
|
|
Set NodeItem = nodeRoot.AppendChild(.CreateElement(key))
|
|
Next
|
|
End IF
|
|
|
|
End With
|
|
|
|
End Function
|
|
|
|
'// 모든 에러 메세지 출력
|
|
Public Function XmlError(ErrStr)
|
|
Dim textMessage,textError
|
|
|
|
textMessage = ""
|
|
With m_DOM
|
|
|
|
.async = False
|
|
.appendChild(.createProcessingInstruction("xml","version=""1.0"" encoding=""utf-8"" "))
|
|
|
|
Set nodeRoot = .AppendChild(objXml.CreateElement("root_data"))
|
|
Set nodeItem = nodeRoot.AppendChild(objXml.CreateElement("item"))
|
|
Set nodeMessage = nodeItem.AppendChild(objXml.CreateElement("message"))
|
|
Set nodeError = nodeItem.AppendChild(objXml.CreateElement("error"))
|
|
|
|
textMessage = "에러 발생" & ErrStr
|
|
textError = 1
|
|
|
|
nodeMessage.Text = .createCDATASection(textMessage).text
|
|
nodeError.Text = textError
|
|
|
|
End With
|
|
End Function
|
|
|
|
End Class
|
|
|
|
|
|
%> |