1

Question: suppose you have a XML

<rootelement>
  <transaction>
    <code>not found</code>
    <status>404</status>
  </transaction>
  <data>
      <item>Whatever</item>
  </data>
</rootelement>

And another XML file:

<rootelement2>
  <transaction>
    <code>not found</code>
    <status>404</status>
  </transaction>
  <searchresult>
    <item>Whatever</item>
  </searchresult>
</rootelement2>

Now, furthermore suppose the tags transaction, searchresult and data are not present, and therefore, their child elements have a namespace instead.

(See here Serializing XML with strange namespaces?)

Is there a way I can have one class for everything transaction, one class for everything data, and one class for everything searchresult, and then create a class SearchResultRequest which encapsulates transaction + its own respective content (without the enclosing tags <transaction> and <searchresult>),

Something like

class SearchResultRequest
{
    <XML_SerializeContentOnly_Here()>
    public cTransaction Transaction = new cTransaction();

    <XML_SerializeContentOnly_Here()>
    public cSearchResult SearchResult = new cSearchResult();
}
3
  • Can you explain: Is there a way I can have one class for everything transaction, one class for everything data, and one class for everything searchresult, Commented Aug 17, 2011 at 12:38
  • For your result class, you might try using XElement.Load() for each set and adding the returned XElement to your results. Commented Aug 17, 2011 at 13:48
  • Can you write up an example, of how you want a resulting XML to look like, and how resulting class(es) would look like? Commented Aug 29, 2011 at 18:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.