Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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




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>

Posted
Updated 5-May-10 13:34pm
v2

And the XML that causes the error ( and obviously contains an invalid character ) is ?
 
Share this answer
 
Looking for a list of invalid characters for XML.

Is there VB code that can parse the characters?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900