Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem reading XML

1 view
Skip to first unread message

David McCallum

unread,
Dec 13, 2009, 6:20:06 AM12/13/09
to
I've just started playing with XML and have come across a problem with a
simple program I wrote, I get an XmlException "Root element is missing" at
the ReadXml line.

Can anyone tell me what I have done wrong?

CODE
===================================================================
var post = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
"<Manufacturers>" +
" <Manufacturer>" +
" <manufacturerId>1</manufacturerId>" +
" <manuName>AC</manuName>" +
" <hidden>false</hidden>" +
" <lockVersion>0</lockVersion>" +
" </Manufacturer>" +
" <Manufacturer>" +
" <manufacturerId>2</manufacturerId>" +
" <manuName>ALFA ROMEO</manuName>" +
" <hidden>false</hidden>" +
" <lockVersion>0</lockVersion>" +
" </Manufacturer>" +
"</Manufacturers>";
var input = new StringReader(post);
var rdr = new XmlTextReader(input);
var ds = new DataSet();
ds.ReadXml(input);
===================================================================


TIA

David McCallum

Martin Honnen

unread,
Dec 13, 2009, 7:09:09 AM12/13/09
to

Remove that line above, you are not using the XmlTextReader anyway, but
it messes with the StringReader you want to feed to the ReadXml method.

> var ds = new DataSet();
> ds.ReadXml(input);

--

Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/

David McCallum

unread,
Dec 13, 2009, 8:13:12 AM12/13/09
to

> Remove that line above, you are not using the XmlTextReader anyway, but
> it messes with the StringReader you want to feed to the ReadXml method.
>
>> var ds = new DataSet();
>> ds.ReadXml(input);
>
>
>
> --
>
> Martin Honnen --- MVP XML
> http://msmvps.com/blogs/martin_honnen/

Thanks Martin.

0 new messages