Excel VBA DOMDocument から XML にデータをエクスポートするときに空白を追加しようとしています。
通常のノードと任意のタイプの要素の間でこれらを正常に実行できますが、要素の 2 つの属性の間に改行とインデント用の空白を追加したいと思います。
例:これを入手...
<elements>
<element id="idvalue">
<subelement id="idvalue" item-type="10" store-category="3" purchase-limit="1" min-roster-space="4" ui-headerbg="tex.icon" ui-icon="tex.coolicon">
こんな姿に…
<elements>
<element id="idvalue">
<subelement id="idvalue" item-type="10" store-category="3"
purchase-limit="1" min-roster-space="4" ui-headerbg="tex.icon"
ui-icon="tex.coolicon">
通常の要素でこれを行うのは、次のようなコードを使用するとかなり簡単です。
parentElement.InsertBefore _
parentElement.OwnerDocument.createTextNode(strElementFormat), _
parentElement.ChildNodes.Item(0)
また
parentElement.appendChild _
parentElement.OwnerDocument.createTextNode(strLastElementFormat)
属性をノードとして繰り返したり、親要素を使用する前に挿入したりしてみました。
次のように、2 番目のテキスト要素を属性値の一部として扱うようです。
<item id="2024_MINNOW_CONVERSION" item-type="10" store-category="3" purchase-limit="1
 " min-roster-space="4">
このコード スニペットの使用:
Sub formatXMLAttributes(currentElement As MSXML2.IXMLDOMElement, _
toolXMLDoc As MSXML2.DOMDocument60, _
Indent As Integer)
Dim attributeNode As MSXML2.IXMLDOMNode, _
intIndex As Integer, _
strElementFormat As String
intIndex = 0
strElementFormat = vbCrLf & Space$(Indent * 4)
For Each attributeNode In currentElement.Attributes
intIndex = intIndex + 1
If intIndex Mod 4 = 0 And currentElement.Attributes.Length > 4 Then
attributeNode.appendChild _
attributeNode.OwnerDocument.createTextNode(strElementFormat)
End If
Next
End Sub
何かご意見は?私の疑いは、それがサポートされていないということです