Click here to Skip to main content
15,923,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
[XmlElement(DataType = typeof(string)),
XmlElement(DataType = typeof(int))]
public object[] StringsAndInts;


This code is not working when i converting xmldata to object using XmlElement in c#.net ?

Could you pls advise me, How can I convert xml data using XmlElement(without XmlElementAttribute).
Posted

This is VB code. Perhaps you need to tell us how you wrote it in C# ? What are you trying to do ? I see an XmlElement as a member. I had no idea XmlElement could be a generic type, although it makes sense and is kind of cool. What are you trying to do exactly ? Will this throw an exception if the data is not an int ? I would stick with the base XmlElement and use int.TryParse to see if the data inside it is an int.
 
Share this answer
 
The InnerXml property of the node in question will give you that.
 
Share this answer
 
You should not keep posting answers to yourself.

You can google XmlElement, or XmlDocument, to find any documentation you need. XPath is what you use to find nodes in a DOM document. You should perhaps buy a book on XML and read it, I did, and that's why I know all of this without reference to any sort of book or article.
 
Share this answer
 
Thanks for your response.
What Actually I wanna do is Whilst deserialing an XML I want a portion of the XML to be returned as RAW XML String..

Example
<Person>
<Name>Babuji</Name>
<Location>SG</Location>
<OtherDetails>
<Data>
<Sex>M</Sex>
<Experience>7</Experience>
..
<Hobby>Surfing<Hobby>
</Data>
</OtherDetails>
</person>

I need the OtherDetails as Raw XML String. Something like this..
Class Person
{
public string Name;
public string Location;
public List<string> OtherDetails;
}
I would expect the OtherDetails to have
<Data>
<Sex>M</Sex>
<Experience>7</Experience>
..
<Hobby>Surfing<Hobby>
</Data>
 
Share this answer
 
v2
Please help to provide any link for this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900