Alex_Piggy
Advanced Member | Редактировать | Профиль | Сообщение | ICQ | Цитировать | Сообщить модератору Const isMSXML60 = false Dim oXML If isMSXML60 Then Set oXML = CreateObject("MSXML2.DomDocument.6.0") Else Set oXML = CreateObject("MSXML2.DomDocument") End If oXML.LoadXML "<?xml version='1.0' encoding='UTF-8'?><InterfaceSSHConfig xmlns:g='urn:1'/>" Dim oChannel, oRTU, oStatuses, oAnalogs Set oChannel = CreateChild (oXML.documentElement, "CHANNEL", "") oChannel.setAttribute "ChannelNum", "3" oChannel.setAttribute "ChannelName", "БМИУ" Set oRTU=CreateChild(oChannel, "RTU", "") oRTU.setAttribute "RTUName", "Инвертор 1" oRTU.setAttribute "RTUNum", "1" Set oStatuses = CreateChild(oRTU, "STATUSES", "") oStatuses.setAttribute "StaDesc", "Инвертор1" With CreateChild(oStatuses, "STATUS", "") .setAttribute "StatusPoint", "1" .setAttribute "StatusName", "Связь с инвертором" .setAttribute "StatusClass", "12" .setAttribute "StatusInvert", "+ (да)" .setAttribute "StatusImp", "2 (сигнал)" End With With CreateChild(oStatuses, "STATUS", "") .setAttribute "StatusPoint", "2" .setAttribute "StatusName", "Повреждение изоляции" .setAttribute "StatusInvert", "+ (да)" End With Set oAnalogs = CreateChild(oRTU, "ANALOGS", "") oAnalogs.setAttribute "AnaDesc", "Инвертор1" With CreateChild(oAnalogs, "ANALOG","") .setAttribute "AnalogPoint", "1" .setAttribute "AnalogName", "Генерация за текущие сутки" .setAttribute "AnalogUnits", "Мвт*ч" End With With CreateChild(oAnalogs, "ANALOG","") .setAttribute "AnalogPoint", "2" .setAttribute "AnalogName", "Генерация полная" .setAttribute "AnalogUnits","МВт*ч" End With CreateChild oAnalogs, "g:xmlnsTest", "bla-bla-bla" oXML.Save "result.xml" Function CreateChild(oParent, vCode, vValue) If isMSXML60 Then Set CreateChild = CreateChild60(oParent, vCode, vValue) Else Set CreateChild = CreateChild30(oParent, vCode, vValue) End If End Function Function CreateChild60(oParent, vCode, vValue) Dim oTMP, oNameSpace, vNameSpace, vColonPos vColonPos = InStr(vCode, ":") Set oNameSpace = oParent.ownerDocument.DocumentElement.getAttributeNode("xmlns") If Not oNameSpace Is Nothing Then vNameSpace = oNameSpace.Text If vColonPos > 0 Then Set oNameSpace = oParent.ownerDocument.DocumentElement.getAttributeNode("xmlns:" & Mid(vCode, 1, vColonPos - 1)) If Not oNameSpace Is Nothing Then vNameSpace = oNameSpace.Text End If Set oTMP = oParent.ownerDocument.createNode(1, vCode, vNameSpace) If vValue <> "" Then oTMP.Text = vValue oParent.appendChild oTMP Set CreateChild60 = oTMP Set oTMP = Nothing End Function Function CreateChild30(oParent, vCode, vValue) Dim oTMP, oNameSpace Set oTmp = oParent.ownerDocument.createElement(vCode) If vValue <> "" Then oTMP.Text = vValue oParent.appendChild oTMP Set CreateChild30 = oTMP Set oTMP = Nothing End Function |