0

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

2
Contributors
5
Replies
15
Views
4 Years
Discussion Span
Last Post by anisha.silva
0

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

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.