469,304 Members | 1,888 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,304 developers. It's quick & easy.

XMLTextReader - root element is missing

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

End Try
Nov 12 '05 #1
4 13519
Cheryl Gilbert wrote:
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.


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

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
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

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:OV**************@TK2MSFTNGP12.phx.gbl...
Cheryl Gilbert wrote:
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.


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

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #3
Cheryl Gilbert wrote:
There is nothing before the root element. I've printed the string to the
debug widow, and validated the string in XMLSpy


Well, can you show some repro?

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #4
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

"Cheryl Gilbert" <cg******@financialfreedom.com> wrote in message
news:en**************@TK2MSFTNGP12.phx.gbl...
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

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:OV**************@TK2MSFTNGP12.phx.gbl...
Cheryl Gilbert wrote:
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.


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

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com


Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Blaz Lipuscek | last post: by
4 posts views Thread by Meir S. | last post: by
5 posts views Thread by Geoff Bennett | last post: by
2 posts views Thread by Yuriy | last post: by
2 posts views Thread by pesso | last post: by
2 posts views Thread by CindyH | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.