Классический атрибут asp create xml повторяется во втором теге - PullRequest
0 голосов
/ 14 декабря 2018

Использование следующего кода для создания простого XML-документа в классическом asp:

dim xmlDoc: set xmlDoc = server.createobject("Microsoft.XMLDOM")
dim objRoot,objRecord,objAttribute,objIntro,objChild
dim newFileName: newFileName = "testing"
strFolder = server.mappath("/")

set objRoot = xmlDoc.createElement("Document")
set objAttribute = xmlDoc.createAttribute("xmlns")
objAttribute.nodeValue = "urn:iso:std:iso:20022:tech:xsd:pain.008.001.02"
objRoot.setAttributeNode(objAttribute)
xmlDoc.appendChild objRoot

set objRecord = xmlDoc.createElement("Level1-1")
objRoot.appendChild objRecord

set objRecord = xmlDoc.createElement("Level1-2")
objRoot.appendChild objRecord

set objRecord = xmlDoc.createElement("Level1-3")
set objChild = xmlDoc.createElement("Level1-3-1")
objChild.text = "Level1-3-1"
objRecord.appendChild objChild

objRoot.appendChild objRecord

Set objIntro = xmlDoc.createProcessingInstruction("xml","version='1.0' encoding='UTF-8'")  
xmlDoc.insertBefore objIntro,xmlDoc.childNodes(0)  
xmlDoc.save (strFolder & "\userdata\file\" & newFileName & ".xml")
response.write "<a href=""/userdata/file/" & newFileName & ".xml"" target=""_blank"">Open XML</a>"
set xmlDoc = nothing

Это дает следующий результат:

<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.02">
    <Level1-1 xmlns=""/>
    <Level1-2 xmlns=""/>
    <Level1-3 xmlns="">
        <Level1-3-1>Level1-3-1</Level1-3-1>
    </Level1-3>
</Document>

Как вы можете видеть созданный атрибутна корневом элементе Document повторяется в каждом теге второго уровня.Хотя это не было создано в коде.На третьем уровне (уровень 1-3) нет атрибута.

Кто-нибудь есть идеи, почему это происходит?И как этого избежать?

спасибо Walther

1 Ответ

0 голосов
/ 19 декабря 2018

Вы можете использовать setAttribute Method , чтобы добавить атрибут и его значение к этому конкретному элементу.

objRoot.setAttribute "xmlns","urn:iso:std:iso:20022:tech:xsd:pain.008.001.02" 
...