用xmlwriter编写xmlns条目的问题

时间:2019-02-08 16:08:44

标签: xml vb.net visual-studio-2017 xmlwriter

我的.xml文件中确实需要此标头:

unsigned long currentVCIndex = [self.navigationController.viewControllers indexOfObject:self.navigationController.topViewController];

//previous view controller
UIViewController *view = (UIViewController *)[self.navigationController.viewControllers objectAtIndex:currentVCIndex - 1];

if([view isKindOfClass:[CustomViewController class]])
{
    [self runSomething];
}

我无法根据需要创建文件,因为xmlwriter在我的所有尝试中都抛出了错误(尝试了整整一天以来我发现的所有内容)。
这里缺少什么-如何根据需要生成文件? 代码已截断:

<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">

谢谢您的提示。

1 个答案:

答案 0 :(得分:0)

经过反复尝试,我自己找到了解决方案:

代码:

Dim cNameSpace As String = "http://www.xxxxx.ch/schema/2.1"
Dim cSchemaInstance As String = "http://www.w3.org/2001/XMLSchema-instance"
'
Using writer As XmlWriter = XmlWriter.Create(cFileExport, settings)
  writer.WriteStartDocument()
  writer.WriteStartElement("document", cNameSpace) ------
  writer.WriteAttributeString("xmlns", "xsi", "http://www.w3.org/2000/xmlns/", cSchemaInstance)
  writer.WriteAttributeString("xsi", "schemaLocation", cSchemaInstance, "http://www.xxxxx.ch/schema/2.1 http://www.xxxxx.ch/schema/xxxxx_2.1.01.xsd")

生成:

<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xsi:schemaLocation="http://www.xxxxx.ch/schema/2.1  
http://www.xxxxx.ch/schema/eSchKG_2.1.01.xsd"  
xmlns="http://www.xxxxx.ch/schema/2.1">

与示例中的顺序不完全相同,但这无关紧要...
现在,该文件已从系统中被确认为有效文件,我必须将该文件发送至该文件。