Click here to Skip to main content
16,014,392 members
Home / Discussions / C#
   

C#

 
GeneralRe: Regular Expression to convert from PHP to C# [modified] Pin
Graham Nimbley26-Jun-06 11:56
Graham Nimbley26-Jun-06 11:56 
GeneralRe: Regular Expression to convert from PHP to C# Pin
AngryC26-Jun-06 12:34
AngryC26-Jun-06 12:34 
GeneralRe: Regular Expression to convert from PHP to C# [modified] Pin
Graham Nimbley26-Jun-06 13:05
Graham Nimbley26-Jun-06 13:05 
GeneralRe: Regular Expression to convert from PHP to C# [modified] Pin
AngryC26-Jun-06 13:16
AngryC26-Jun-06 13:16 
GeneralRe: Regular Expression to convert from PHP to C# Pin
Graham Nimbley26-Jun-06 13:21
Graham Nimbley26-Jun-06 13:21 
GeneralRe: Regular Expression to convert from PHP to C# Pin
AngryC26-Jun-06 13:30
AngryC26-Jun-06 13:30 
GeneralRe: Regular Expression to convert from PHP to C# Pin
Graham Nimbley26-Jun-06 13:41
Graham Nimbley26-Jun-06 13:41 
QuestionDeserialize XML by reverse-engineering class def Pin
Ed 5425-Jun-06 5:18
Ed 5425-Jun-06 5:18 
Can I deserialize XML into an object by reverse-engineering the class definition from a sample XML document, if I don't have the actual class definition from which the XML was serialized?

I'm making function calls to the Google Maps API geocoder using an HTTP request. The function call returns an XML file, which I want to extract data from.

Here are the first few lines of the XML file:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
    <Response>
        <name>1600 Amphitheatre Parkway, Mountain View,CA</name>
        ....

And here are the first few lines of the class definition that I reverse-engineered from the XML:
[XmlRootAttribute(ElementName = "kml", IsNullable = false)]
    public class kmlJSON
    {
        public kmlJSON() { }
        public class Response
        {
            public String name;
            ....

Here is my C# routine to deserialize the data into an object of kml class:
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
XmlSerializer xs = new XmlSerializer(typeof(kmlJSON));
kmlJSON jsonObject = new kmlJSON();
jsonObject = (kmlJSON)xs.Deserialize(resStream);  //try-catch block omitted for brevity

When I run it, I get the following error at jsonObject = (kmlJSON)xs.Deserialize(resStream); :
[InvalidOperationException: <kml xmlns='http://earth.google.com/kml/2.0'> was not expected.]
   Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderkmlJSON.Read3_kml() +91
[InvalidOperationException: There is an error in XML document (1, 40).]

Any ideas why XmlDeserializer is getting stuck on the root declaration of the XML file? Am I missing something simple, or must I have the exact class definition that the XML was serialized from?
AnswerRe: Deserialize XML by reverse-engineering class def Pin
Guffa25-Jun-06 6:35
Guffa25-Jun-06 6:35 
GeneralRe: Deserialize XML by reverse-engineering class def Pin
Ed 5425-Jun-06 16:48
Ed 5425-Jun-06 16:48 
AnswerRe: Deserialize XML by reverse-engineering class def Pin
Guffa25-Jun-06 18:52
Guffa25-Jun-06 18:52 
GeneralRe: Deserialize XML by reverse-engineering class def Pin
Ed 5426-Jun-06 12:57
Ed 5426-Jun-06 12:57 
QuestionUnderstanding DataSets... [modified] Pin
martin_hughes25-Jun-06 4:56
martin_hughes25-Jun-06 4:56 
AnswerRe: Understanding DataSets... Pin
Robert Rohde25-Jun-06 20:10
Robert Rohde25-Jun-06 20:10 
QuestionOptional field selection SQL Pin
WillemM25-Jun-06 4:30
WillemM25-Jun-06 4:30 
AnswerRe: Optional field selection SQL Pin
Michael P Butler25-Jun-06 5:04
Michael P Butler25-Jun-06 5:04 
GeneralRe: Optional field selection SQL Pin
WillemM25-Jun-06 5:28
WillemM25-Jun-06 5:28 
Questionbug in HScrollBar control object Pin
3Dizard25-Jun-06 4:17
3Dizard25-Jun-06 4:17 
AnswerRe: bug in HScrollBar control object [modified] Pin
Graham Nimbley25-Jun-06 10:12
Graham Nimbley25-Jun-06 10:12 
GeneralRe: bug in HScrollBar control object Pin
3Dizard26-Jun-06 4:28
3Dizard26-Jun-06 4:28 
Questionclass or struct? Pin
Super Lloyd25-Jun-06 4:16
Super Lloyd25-Jun-06 4:16 
AnswerRe: class or struct? Pin
Jun Du25-Jun-06 4:39
Jun Du25-Jun-06 4:39 
GeneralRe: class or struct? Pin
Super Lloyd25-Jun-06 5:10
Super Lloyd25-Jun-06 5:10 
AnswerRe: class or struct? Pin
Guffa25-Jun-06 5:09
Guffa25-Jun-06 5:09 
GeneralRe: class or struct? Pin
Super Lloyd25-Jun-06 5:12
Super Lloyd25-Jun-06 5:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.