Мне приходится использовать двоеточие в атрибуте XML, но все, что стоит перед двоеточием и само двоеточие, всегда игнорируется.
Это мой исходный код:
Dim xmlDoc As New XmlDocument()
Dim rootElement As XmlElement = xmlDoc.CreateElement("export")
rootElement.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
rootElement.SetAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema")
xmlDoc.AppendChild(rootElement)
' Kommentare
Dim comment1 As XmlComment = xmlDoc.CreateComment("Kontentabelle")
rootElement.AppendChild(comment1)
Dim comment2 As XmlComment = xmlDoc.CreateComment(DateTime.Now.ToShortDateString())
rootElement.AppendChild(comment2)
Dim comment3 As XmlComment = xmlDoc.CreateComment("**************************************************************************************************************************************")
rootElement.AppendChild(comment3)
'Konten
For Each abs As Account In lst_Absences
Dim orderElement As XmlElement = xmlDoc.CreateElement("order")
orderElement.SetAttribute("xsi:type", "ExportAccountListItemExportCalendarAbsence")
orderElement.SetAttribute("absence", abs.int_AccountNumber.ToString())
orderElement.SetAttribute("code1", abs.int_AccountNumber.ToString())
orderElement.SetAttribute("code2", abs.str_AccountName.ToString)
orderElement.SetAttribute("code3", abs.str_AccountShort.ToString)
rootElement.AppendChild(orderElement)
Next
Подробно это касается атрибута «xsi:type»; однако в выводе остается только «тип»:
<export xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
<!--Kontentabelle-->
<!--11.03.2024-->
<!--**************************************************************************************************************************************-->
<order type = "ExportAccountListItemExportCalendarAbsence" absence = "1" code1 = "1" code2 = "SampleAbsence" code3 = "SA" />
</export>
xsi:type используется, когда у вас есть класс, унаследованный от базового класса. Вам нужно использовать XmlInclude: см. следующий пример С# Learn.microsoft.com/en-us/dotnet/api/…





Попробуйте этот формат
orderElement.SetAttribute("type", "http://www.w3.org/2001/XMLSchema-instance", "ExportAccountListItemExportCalendarAbsence")
Я не знаю VB, но в большинстве языков с DOM API вы можете использовать SetAttributeNS для создания атрибута, имя которого находится в пространстве имен.