473,569 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ByV al sXML As String) As String

Dim strReader As StringReader
strReader = New StringReader(sX ML)

Dim tr As XmlTextReader = New XmlTextReader(s trReader)
Dim sc As XmlSchemaCollec tion = New XmlSchemaCollec tion
Dim vr As XmlValidatingRe ader = New XmlValidatingRe ader(tr)

Try

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

AddHandler vr.ValidationEv entHandler, AddressOf ValidationCallB ack

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 13762
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!P LEASEtkachenko. com> wrote in message
news:OV******** ******@TK2MSFTN GP12.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******@finan cialfreedom.com > wrote in message
news:en******** ******@TK2MSFTN GP12.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!P LEASEtkachenko. com> wrote in message
news:OV******** ******@TK2MSFTN GP12.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
3320
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 xml to this post (bellow) for better understanding. When I use ReadInnerXml method when reader is at <text> element it returns a string : <c>ABC</c>....
4
5357
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 command, so I have to parse and execute them according to the order they appear in the ROOT element. I don't want to use XmlDocument for the...
1
1914
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 reader = new XmlTextReader(stm); reader.XmlResolver = null; // no DTD/schema, high perf while (reader.Read()){ switch (reader.NodeType){ default:
1
1581
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"/> </Course> <Course CourseCode="id2">
5
9195
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 RelatedID="118"/> <PersonName> <NameTitle Value="Mr"/> <FirstName>Clint</FirstName> <OtherName/> <AlsoKnownAs>Mr C Eastwood</AlsoKnownAs>
2
4160
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
4419
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 matching the filters, runs into the response.write and outputs nothing. I've used the dbgclr to verify that the filters are matching and it is hitting...
2
4076
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 try to load that into XmlTextReader, it throws XmlException. I'd appreciate your help. //create file stream to read encrypted file back...
2
1414
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" AMOUSERNAME="Billy hill" AMOAROLES="Student" AMOAPRODUCTS="intralase,VISX,ILASKI" /> </userlist>
0
7700
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7974
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.