Groups | Blog | Home
all groups > dotnet xml > september 2004 >

dotnet xml : XMLTextReader - root element is missing


cheryl NO[at]SPAM cherylgilbert.com
9/21/2004 2:41:58 PM
I'm sending xml to a web service by building a string dynamically.
When my web service tries to validate the xml with a schema, I'm
getting the error "the root element is missing". If I use an xml file
saved to disk, I don't get an error.

Does anyone know what the problem could be?

- Cheryl

Public Function ValidateXML(ByVal sXML As String) As String

Dim strReader As StringReader
strReader = New StringReader(sXML)

Dim tr As XmlTextReader = New XmlTextReader(strReader)
Dim sc As XmlSchemaCollection = New XmlSchemaCollection
Dim vr As XmlValidatingReader = New XmlValidatingReader(tr)

Try

sc.Add(Nothing, "c:\FFRMA\Test.xsd")
vr.ValidationType = ValidationType.Schema
vr.Schemas.Add(sc)

AddHandler vr.ValidationEventHandler, AddressOf ValidationCallBack

While (vr.Read())

End While

sErrorMsg = "Success"

Catch ex As Exception

sErrorMsg = ex.Message & ":" & ex.Source

Finally

ValidateXML = sErrorMsg

Oleg Tkachenko [MVP]
9/22/2004 2:15:41 PM
[quoted text, click to view]

Must be some junk before root element. Debug and see what is passed
string. It might be also encoding issue.

--
Oleg Tkachenko [XML MVP]
Cheryl Gilbert
9/23/2004 2:21:56 PM
There is nothing before the root element. I've printed the string to the
debug widow, and validated the string in XMLSpy

What possible encoding issue could it be?

Thank you,

Cheryl

[quoted text, click to view]

Oleg Tkachenko [MVP]
9/26/2004 10:27:27 AM
[quoted text, click to view]

Well, can you show some repro?

--
Oleg Tkachenko [XML MVP]
Amol Kher [MSFT]
11/22/2004 2:27:56 PM
Does it provide you any line information where this is happening? If its an
encoding issue, its generally after the xml declaration. However seeing the
line information may help? Send the XML if you want us to take a look.

Thanks,
Amol

[quoted text, click to view]

AddThis Social Bookmark Button