XML validation error. Help required

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • stuart dent via .NET 247

    XML validation error. Help required

    XML validation error. Help required
    If anyone can help me, thankyou, thankyou...

    When I run this code code I get this error:
    The data at the root level is invalid. Line 1, position 39.

    I can't work out what the error is. Can you???

    original code:
    Dim oRead As XmlTextReader
    Dim oValid As XmlValidatingRe ader

    Try
    oRead = New XmlTextReader(" C:\custdoc.xml" )
    oValid = New XmlValidatingRe ader(oRead)

    AddHandler oValid.Validati onEventHandler, New Schema.Validati onEventHandler( AddressOf ValidationError )
    oValid.Schemas. Add("newschema" , "C:\custschema. xsd")
    oValid.Validati onType = ValidationType. Auto

    Do While oValid.Read
    'let validation do its thing
    Loop...


    xml doc file:
    <?xml version="1.0" encoding="UTF-8"?>
    <myroot xmlns:xx="gener ic">
    <xx:Customer>
    <xx:ID>"000001" </xx:ID>
    <xx:Name>"CustO ne"</xx:Name>
    </xx:Customer>
    <xx:Customer>
    <xx:ID>000002 </xx:ID>
    <xx:Name>CustTw o</xx:Name>
    </xx:Customer>
    </myroot>

    xml schema file:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="generic" elementFormDefa ult="qualified" targetNamespace ="generic">
    <xs:element name="myroot">
    <xs:complexType >
    <xs:choice maxOccurs="unbo unded">
    <xs:element name="Customer" >
    <xs:complexType >
    <xs:sequence>
    <xs:element name="ID" type="xs:string " minOccurs="0" />
    <xs:element name="Name" type="xs:string " minOccurs="0" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:choice>
    </xs:complexType>
    </xs:element>
    </xs:schema>

    Thanks, Stu
    --------------------------------
    From: stuart dent

    -----------------------
    Posted by a user from .NET 247 (http://www.dotnet247.com/)

    <Id>pVvJYVwbZUe vEQlnr5NghQ==</Id>
  • Derek Harmon

    #2
    Re: XML validation error. Help required

    "stuart dent via .NET 247" <anonymous@dotn et247.com> wrote in message news:OUCL5P1mEH A.2076@TK2MSFTN GP15.phx.gbl...[color=blue]
    > When I run this code code I get this error:
    > The data at the root level is invalid. Line 1, position 39.[/color]
    : :[color=blue]
    > <?xml version="1.0" encoding="UTF-8"?>[/color]

    Anytime you receive an XmlException where the position is at the very end of the XML declaration,
    the XML declaration has no syntax errors, and that XML declaration has an "encoding" pseudo-
    attribute, then it means the file is _not_ whatever that encoding pseudo-attribute says.

    Therefore, the file is not UTF-8 encoded. Try loading it into Notepad and then doing File | Save As..
    and choosing UTF-8 from the Encoding drop-down box. Alternately, change the encoding pseudo-
    attribute to indicate what the encoding of the file truly is.

    The file that's the culprit depends on whether the XmlException was thrown from the XmlTextReader
    (it's then the instance document that has the invalid encoding) or the Add( ) to the XmlSchemaCollec tion
    (it's then the schema document that has the invalid encoding).


    Derek Harmon


    Comment

    Working...