Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
1.44/5 (3 votes)
See more:
how can this be done with "XDocument","XElement", "XNode"... Plz help...

XML STRUCTURE:
XML
<Body>
  <getBooksResponse xmlns="http://tempuri.org/">
    <getBooksResult>
      <T>book2     </T>
      <A>author2   </A>
      <P>10</P>
    </getBooksResult>
  </getBooksResponse>
</Body>


1. Remove Node with "Response" where "getBook" can be generic eg : "getMapResponse" etc.
XML
&<getBooksResponse xmlns="http://tempuri.org/">


2. Replace the Node "XXXXResult" with "Book"
Posted
Updated 4-Apr-13 3:19am
v2

1 solution

It's easy to create the Format using the "fluent" constructors of XDocument, XElement, ...

You can do it like this:

C#
public static XDocument CreateDocument()
        {
            return new XDocument(
                 new XElement("Body",
                     new XElement("getBooksResponse", new XAttribute("ns", "http://tempuri.org/"),
                         new XElement("getBooksResult",
                             new XElement("T", "book2"),
                             new XElement("A", "author2"),
                             new XElement("P", "10")
                         )
                     )
                  )
              );
        }


(If you'd name your attribute xmlns the XML is invalid)

Sorry I don't understand what you mean with Point 1,2...

But I'd suggest to use a class hierarchy representing your data, and use DataContractSerializer to produce the XML.
 
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