【发布时间】:2019-02-08 16:08:43
【问题描述】:
我的 .xml 文件中正好需要这个标头:
<document xsi:schemaLocation="http://www.xxxxx.ch/schema/2.1
http://www.xxxxx.ch/schema/xxxxx_2.1.01.xsd"
xmlns="http://www.xxxxx.ch/schema/2.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
我无法根据需要创建文件,因为 xmlwriter 在我的所有尝试中都抛出了错误(从一整天以来我尝试了所有我发现的东西)。
这里缺少什么 - 如何根据需要生成文件?
代码截断:
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.Indent = True
settings.CloseOutput = True
Dim cFileExport As String = cTempAblagenPfad + cFilenameExport_XML
Using writer As XmlWriter = XmlWriter.Create(cFileExport, settings)
writer.WriteStartDocument()
'
writer.WriteStartElement("document")
writer.WriteAttributeString("xsi", "schemaLocation", vbNull, "http://www.xxxxx.ch/schema/2.1 http://www.xxxxx.ch/schema/xxxxx_2.1.01.xsd")
' Generates XML: <document xsi:schemaLocation="http://www.xxxxx.ch/schema/2.1 http://www.xxxxx.ch/schema/xxxxx_2.1.01.xsd" xmlns:xsi="1">
' I have no idea, why xmlns:xsi="1" is generated by the xml-writer - maybe that’s the problem?
writer.WriteAttributeString("xmlns", "http://www.xxxxx.ch/schema/2.1", XmlSchema.InstanceNamespace)
' throws: "The prefix "xmlns" is reserved for XML
writer.WriteAttributeString("xmlns", "http://www.xxxxx.ch/schema/2.1")
' throws: "the prefix '' cannot be changed from '' to 'http://www.xxxxx.ch/schema/2.1' in the same startelement tag"
writer.WriteAttributeString("xmlns", "xsi", vbNull, "http://www.w3.org/2001/XMLSchema-instance")
‘throws: "The prefix "xmlns" is reserved for XML
....
感谢任何提示..
【问题讨论】:
-
例外?你的问题没有例外。或许您应该 edit 并将它们包括在内,这样人们就可以看到出了什么问题。
-
我已将文本中的“异常”更改为“错误” - 错误消息在代码中以 cmets 的形式出现(从德语翻译成英语)
标签: xml vb.net visual-studio-2017 xmlwriter