My problem, is serializing the array of BookData objects and putting attributes into the array wrapper tag <BookList>. Right now, I'm just using a custom object called BookList to add attributes to the element, but this only allows for 1 <BookData> tag inside of it, which will not work if I get back an array of BookData elements.
I'd like to have an object called ISBNdb, with an array of BookData objects inside of it and have the attributes "total_results", etc. get put inside of the BookList tag as attributes.
This is the code I have right now:
Expand|Select|Wrap|Line Numbers
- public class ISBNdb
- {
- [XmlAttribute]
- public string server_time
- {
- get { return _server_time.ToString("u"); }
- set { _server_time = DateTime.Parse(value); }
- }
- [XmlIgnore]
- private DateTime _server_time;
- public BookList BookList;
- }
- public class BookList
- {
- [XmlAttribute]
- public uint total_results;
- [XmlAttribute]
- public uint page_size;
- [XmlAttribute]
- public uint page_number;
- [XmlAttribute]
- public uint shown_results;
- public BookData BookData;
- }
- public class BookData
- {
- [XmlAttribute]
- public string book_id;
- [XmlAttribute]
- public string isbn;
- public string Title;
- public string TitleLong;
- public string AuthorsText;
- public PublisherText PublisherText;
- }
- public class PublisherText
- {
- [XmlText]
- public string Publisher;
- [XmlAttribute]
- public string publisher_id;
- }
Below is the XML response I get back from isbndb.com
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" encoding="UTF-8"?>
- <ISBNdb server_time="2007-12-23T13:54:18Z">
- <BookList total_results="1" page_size="10" page_number="1" shown_results="1">
- <BookData book_id="to_kill_a_mockingbird_a02" isbn="0060194995">
- <Title>To kill a mockingbird</Title>
- <TitleLong></TitleLong>
- <AuthorsText>Harper Lee</AuthorsText>
- <PublisherText publisher_id="harpercollinspublishers">New York : HarperCollinsPublishers, 1995.</PublisherText>
- </BookData>
- </BookList>
- </ISBNdb>
Expand|Select|Wrap|Line Numbers
- public class ISBNdb
- {
- [XmlAttribute]
- public string server_time
- {
- get { return _server_time.ToString("u"); }
- set { _server_time = DateTime.Parse(value); }
- }
- [XmlIgnore]
- private DateTime _server_time;
- [XmlAttribute]
- public uint total_results;
- [XmlAttribute]
- public uint page_size;
- [XmlAttribute]
- public uint page_number;
- [XmlAttribute]
- public uint shown_results;
- [XmlArray]
- public BookData[] BookList;
- }
- public class BookData
- {
- [XmlAttribute]
- public string book_id;
- [XmlAttribute]
- public string isbn;
- public string Title;
- public string TitleLong;
- public string AuthorsText;
- public PublisherText PublisherText;
- }
- public class PublisherText
- {
- [XmlText]
- public string Publisher;
- [XmlAttribute]
- public string publisher_id;
- }
My main issue with my code right now is that arrays don't work right now and they should. Regardless of what my code ends up looking like, I want to be able to get back the BookData as an array so that I am reflecting what isbndb.com is sending me.