473,411 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

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 13754
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Blaz Lipuscek | last post by:
I have a problem with System.Xml.XmlTextReader.ReadInnerXml() Method. By using this method you think it will return a string that contains all child nodes of the current node. I attached a sample...
4
by: Meir S. | last post by:
I think the following is a bug in XmlTextReader: I need to process large XMLs, that are typically constructed of many small elements nested in the root element. Each inner element represents a...
1
by: Koji Ishii | last post by:
I'm trying to read response from a web server using XmlTextReader. Here's a code snippet. WebResponse rs = this.WebRequest.GetResponse(); Stream stm = rs.GetResponseStream(); XmlTextReader...
1
by: Jesper Stocholm | last post by:
I have som XML like this: <root> <Course CourseCode="id1"> <Teacher Name="Some name"/> <Title Titlde="Dansk Titel 1"/> <Title Title="English Title 1"/> <Location Place="Some place"/>...
5
by: Geoff Bennett | last post by:
While parsing an XML document, my TextReader instance skips nodes. For example, in this fragment: <Person Sex="Male" FirstHomeBuyer="No" YearsInCurrentProfession="14"> <RelatedEntityRef...
2
by: Yuriy | last post by:
Hi, any ideas how to read XML fragment from TextReader? XmlTextReader constructor accepts only Stream or string as source Do I miss something? thanks Yuriy
1
by: soupaman | last post by:
Im trying to output some filtered xml using the xmlTextReader I know the code and commenting needs cleaned up and eventually plan to add the values to a dataset. currently what this is doing is...
2
by: pesso | last post by:
I have the following code that's taken and modified from a got_dot_net example. I'm trying to decrypt an Xml file that's been encrypted. I can dump the decrypted stream to the console, but if I...
2
by: CindyH | last post by:
Hi I have a http xml post that I'm trying to read using xmltextreader. This is the xml: <?xml version="1.0"?> <userlist ACTION="newuser" VENDORNAME="H2Digital"> <amouser AMOAID="101"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.