打开XML-VB.Net-错误名称包含无效字符
问题描述:
我创建了一个Word表单,该表单具有三个可访问XML数据的组合框.我不明白为什么会收到以下错误,或者如何正确命名架构或将控件正确绑定到数据:
用户代码未处理COMException-
名称包含无效字符
这是我的Shema:
I created a Word form that has three combo boxes that access XML data. I don''t understand why I''m receiving the following error or how to correctly name the schema or correctly bind the control to the data:
COMException was unhandled by user code -
A name contained an invalid character
Here''s my shema:
<pre lang="msil"><?xml version=''1.0'' encoding=''UTF-16''?>
<!-- Created from XmlMap.Name: Technical_Expertise -->
<!-- XmlMap.DataBinding.SourceUrl: -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element nillable="true" name="Root">
<xsd:complexType>
<xsd:sequence minOccurs="0">
<xsd:element minOccurs="0" maxOccurs="unbounded" nillable="true" name="Row" form="unqualified">
<xsd:complexType>
<xsd:sequence minOccurs="0">
<xsd:element minOccurs="0" nillable="true" type="xsd:string" name="Product_Facility" form="unqualified"/>
<xsd:element minOccurs="0" nillable="true" type="xsd:string" name="Scope" form="unqualified"/>
<xsd:element minOccurs="0" nillable="true" type="xsd:string" name="Services_Processes" form="unqualified"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Public Class ThisDocument
Public techexpXMLPartID As String = String.Empty
Private techexpXMLPart As Office.CustomXMLPart
Private Const prefix As String = "Technical_Expertise"
Private Function GetXMLFromResource() As String
Dim asm As System.Reflection.Assembly = _
System.Reflection.Assembly.GetExecutingAssembly()
Dim stream1 As System.IO.Stream = asm.GetManifestResourceStream( _
"TechnicalExpertise.Technical_Expertise.xml")
Using resourceReader As System.IO.StreamReader = _
New System.IO.StreamReader(stream1)
If resourceReader IsNot Nothing Then
Return resourceReader.ReadToEnd()
End If
End Using
Return Nothing
End Function
Private Sub BindControlsToCustomXmlPart()
Dim xPathProdFac As String = "ns:Technical_Expertise/ns:Root/ns:Product_Facility"
Me.ProdFacCombobx.XMLMapping.SetMapping(xPathProdFac, _
prefix, techexpXMLPart)
Dim xPathScope As String = "ns:Technical_Expertie/ns:Root/ns:Scope"
Me.ScopeComboBx.XMLMapping.SetMapping(xPathScope, _
prefix, techexpXMLPart)
Dim xPathServProc As String = "ns:Technical_Expertise/ns:Root/ns:Services_Processes"
Me.ServProcComboBx.XMLMapping.SetMapping(xPathServProc, _
prefix, techexpXMLPart)
End Sub
Private Sub AddCutomXMlPart(ByVal xmlData As String)
If xmlData IsNot Nothing Then
techexpXMLPart = Me.CustomXMLParts.SelectByID(techexpXMLPartID)
If (techexpXMLPart Is Nothing) Then
techexpXMLPart = Me.CustomXMLParts.Add(xmlData)
techexpXMLPartID = techexpXMLPart.Id
End If
End If
End Sub
Private Sub ThisDocument_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
Dim XmlData As String = GetXMLFromResource()
If XmlData IsNot Nothing Then
AddCutomXMlPart(XmlData)
BindControlsToCustomXmlPart()
End If
End Sub
Private Sub ThisDocument_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
End Sub
End Class
XML的一部分是:
Part of the XML is:
<pre lang="xml"><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Row>
<Product_Facility>AIRPORT</Product_Facility>
<Scope>Academic</Scope>
<Services_Processes>Abatement</Services_Processes>
</Row>
<Row>
<Product_Facility>Airport - General Aviation</Product_Facility>
<Scope>Acceptance </Scope>
<Services_Processes>Acceptance</Services_Processes>
</Row>
<Row>
<Product_Facility>Airport - International Operations</Product_Facility>
<Scope>Access </Scope>
<Services_Processes>Access Control</Services_Processes>
</Row>
<Row>
<Product_Facility>Airport - Military</Product_Facility>
<Scope>Acoustics</Scope>
<Services_Processes>Accounting</Services_Processes>
</Row>
<Row>
<Product_Facility>Airport - Municipal</Product_Facility>
<Scope>Adaptive</Scope>
<Services_Processes>Acquisition</Services_Processes>
</Row>
<Row>
<Product_Facility>Airport - State</Product_Facility>
<Scope>Advanced Public Transportation System (APTS)</Scope>
<Services_Processes>Acreditation</Services_Processes>
</Row>
答
引起错误(显然包含无效字符)的XML是?
And the XML that causes the error ( and obviously contains an invalid character ) is ?
查找XML无效字符的列表.
有可以解析字符的VB代码吗?
Looking for a list of invalid characters for XML.
Is there VB code that can parse the characters?