TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Patrick
NA
3
0
Deserialize XML - Ignore Element - HowTo?
Dec 8 2019 12:56 PM
Hello
I have a XML, like this(there could be many more Message elements):
<
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
response
>
<
Count
>
2Count
>
<
Messages
>
<
Message
>
<
Smstat
>
0Smstat
>
<
Index
>
40005Index
>
<
Phone
>
+4xxxxxxPhone
>
<
Content
>
Test 2Content
>
<
Date
>
2019-12-08 18:13:35Date
>
<
Sca
>
Sca
>
<
SaveType
>
4SaveType
>
<
Priority
>
0Priority
>
<
SmsType
>
1SmsType
>
Message
>
<
Message
>
<
Smstat
>
1Smstat
>
<
Index
>
40004Index
>
<
Phone
>
+4xxxxxx
>
<
Content
>
Test 1Content
>
<
Date
>
2019-12-08 18:13:30Date
>
<
Sca
>
Sca
>
<
SaveType
>
4SaveType
>
<
Priority
>
0Priority
>
<
SmsType
>
1SmsType
>
</
Message
>
</
Messages
>
</
response
>
I'd like to deserialize it, I came up with this code:
[Serializable()]
[System.Xml.Serialization.XmlRoot(
"Messsages"
)]
public
class
Messsages
{
[XmlArray(
"Messsages"
)]
[XmlArrayItem(
"Message"
,
typeof
(Message))]
public
Message[] Car {
get
;
set
; }
}
[Serializable()]
public
class
Message
{
[System.Xml.Serialization.XmlElement(
"Smstat"
)]
public
int
Smstat {
get
;
set
; }
[System.Xml.Serialization.XmlElement(
"Index"
)]
public
int
Index {
get
;
set
; }
[System.Xml.Serialization.XmlElement(
"Phone"
)]
public
string
Phone {
get
;
set
; }
[System.Xml.Serialization.XmlElement(
"Content"
)]
public
string
Content {
get
;
set
; }
[System.Xml.Serialization.XmlElement(
"Date"
)]
public
string
Date {
get
;
set
; }
[System.Xml.Serialization.XmlElement(
"sca"
)]
public
string
sca {
get
;
set
; }
[System.Xml.Serialization.XmlElement(
"SaveType"
)]
public
string
SaveType {
get
;
set
; }
[System.Xml.Serialization.XmlElement(
"Priority"
)]
public
string
Priority {
get
;
set
; }
[System.Xml.Serialization.XmlElement(
"SmsType"
)]
public
string
SmsType {
get
;
set
; }
}
Messsages[] messages =
null
;
XmlSerializer serializer =
new
XmlSerializer(
typeof
(Message[]));
using
(var response = (HttpWebResponse)request.GetResponse())
{
messages = (Messsages[])serializer.Deserialize(response.GetResponseStream());
}
If I do it like this I get an InvalidOperationException telling me that the xml doesn't match due to the "response"
If I have a look on my XML the Messages are inside "
" - so far it makes sense.
My question now is, how can I "ignore" that "response
"? It is unneeded information for me and I just like to finally have only the data that I defined in the two data classes above.
Is there some ignore flag or how could I achieve that?
Thank you for your help!
Reply
Answers (
1
)
how to Disable Friday from datepicker
How can i disable a certain date on datepicker using c#