Hi,

I am getting a xml object from as a web response for getting data from a web page
the content is as :

"      <bookshare>\n  <version>4.1.1</version>\n  <messages/>\n  <book>\n    <metadata>\n      <author>David Flanagan</author>\n      <available-to-download>0</available-to-download>\n      <bookshare-id>21385</bookshare-id>\n      <brief-synopsis>The 1.4 release of Java 2 Standard edition brings a load of new features - and the potential for frustration. Fret not, our new 4th edition has answers. The accelerated introduction lets you start writing code right away, and because the book&apos;s classic quick reference contains all the classes in the essential Java packages, you can find exactly what you need to make Java&apos;s new version work for you.</brief-synopsis>\n      <category>Computers and Internet</category>\n <content-id>21385</content-id>\n      <copyright>2005</copyright>\n      <dtbook-size>6396260</dtbook-size>\n      <freely-available>0</freely-available>\n      <images>0</images>\n      <isbn13>9780596007737</isbn13>\n      <language>English US</language>\n      <publish-date>05122005</publish-date>\n      <publisher>O&apos;Reilly</publisher>\n      <quality>Publisher Quality</quality>\n      <title>Java in a Nutshell, 5th Edition</title>\n    </metadata>\n  </book>\n</bookshare>\n\n    \n"

how do i format this and get the details from the web response?

appreciate a reply
thanks

Recommended Answers

All 5 Replies

thanks will try and see

Hey

for the xml object i get the below string

"      <bookshare>\n  <version>4.1.2</version>\n  <messages>\n    <string>Invalid/Incorrect ISBN number</string>\n  </messages>\n  <status-code>85</status-code>\n</bookshare>\n\n    \n"

and in a bookshare class i have the below code

public class bookshare
{

    [System.Xml.Serialization.XmlElement("version")]
    public string version { set; get; }
    [System.Xml.Serialization.XmlElement("messages")]
    public string messages { set; get; }
    [System.Xml.Serialization.XmlElement("status-code")]
    public string statusCode { set; get; }
    [System.Xml.Serialization.XmlElementAttribute("book",
        Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public book[] b;

    public bookshare()
    {


    }
}

i am able to retrieve the data for version and message, but when i try to retrieve the data for statu-code it give me a nullreference exception
i retrieve the data as

var reader = new StringReader(res);
        var serializer = new XmlSerializer(typeof(bookshare));
        var instance = (bookshare)serializer.Deserialize(reader);

        string version = instance.version.ToString();
        string message = instance.messages.ToString();
        string eCode = instance.statusCode.ToString();

what is the problem to get null? the varaible has a value
thanks appreciate a reply
thanks

You can't call .ToString() in a null object. Check if the var is null before using it.

hi,

the xml string

<bookshare>\n  <version>4.1.2</version>\n  <messages>\n    <string>Invalid/Incorrect ISBN number</string>\n  </messages>\n  <status-code>85</status-code>\n</bookshare>\n\n    \n"

i am trying to get the status-code but it is returning no value

why is returning a null value ? can't figure it out?

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.