Tapan Pattanaik
asked on
Want to Create an Xml format through C# source code.
Want to generate XML though C#, how to achieve it.
<Message>
<Request>
<Detail>
<TranType>Credit</TranType >
<TranAction>Auth</TranActi on>
<Amount>19.99</Amount>
<CurrencyCode>840</Currenc yCode>
</Detail>
<IndustryData>
<Industry>CardNotPresent</ Industry>
<Eci>7</Eci>
</IndustryData>
<Account>
<Pan>4111111111111111</Pan >
<Expiration>1217</Expirati on>
<Postal>197201234</Postal>
<Address>123 Fake Street</Address>
</Account>
</Request>
<Authentication>
<Client>73</Client>
<Source>1</Source>
</Authentication>
</Message>
<Message>
<Request>
<Detail>
<TranType>Credit</TranType
<TranAction>Auth</TranActi
<Amount>19.99</Amount>
<CurrencyCode>840</Currenc
</Detail>
<IndustryData>
<Industry>CardNotPresent</
<Eci>7</Eci>
</IndustryData>
<Account>
<Pan>4111111111111111</Pan
<Expiration>1217</Expirati
<Postal>197201234</Postal>
<Address>123 Fake Street</Address>
</Account>
</Request>
<Authentication>
<Client>73</Client>
<Source>1</Source>
</Authentication>
</Message>
I've had to do this sort of thing with JSON. From the question I'm spit balling here but I would created a class hierarchy to manage building the the message. The structure of XML lends itself to that nicely. Each class<like message> would now the tags it would use to wrap itself as well as each field. An taking it in chunks helped me to work out the user interface.
The approach is fairly strait forward
<Message> cMessage
<Request> cRequest
<Detail> cDetail
<TranType>Credit</TranType> member
<TranAction>Auth</TranAction>member
<Amount>19.99</Amount>
<CurrencyCode>840</CurrencyCode>
</Detail>
<IndustryData> cIndustryData
<Industry>CardNotPresent</Industry>
<Eci>7</Eci>
</IndustryData>
<Account>
<Pan>4111111111111111</Pan>
<Expiration>1217</Expiration>
<Postal>197201234</Postal>
<Address>123 Fake Street</Address>
</Account>
</Request>
<Authentication>
<Client>73</Client>
<Source>1</Source>
</Authentication>
</Message>
The approach is fairly strait forward
Please share with us the source of the input data and its format which will be used to create the XML document.
ASKER
Hi experts,
from the method I am getting xml string like this and I want to Keep inside "<Response>" how will I do that.
string clResponse = EncryptDecrypt.DecryptStri ng(ClText, key, iv);
I am getting xml string like this
<Reference>
<Guid>3TKYN2H3FKN501J</Gui d>
<TranDate>04/11/2014</Tran Date>
<TranTime>12:18:58</TranTi me>
</Reference>
<Result>
<ResponseCode>00</Response Code>
<ResponseText>Query Complete</ResponseText>
</Result>
<QueryResponse>
<Row>
<Client>177</Client>
<Dba>Tarang</Dba>
<Guid>3P9JFLVNFL4VMXN</Gui d>
<TranType>Credit</TranType >
<TranAction>Sale</TranActi on>
<ResponseCode>00</Response Code>
<ResponseText>Approved</Re sponseText >
<FirstName>John</FirstName >
<LastName>Doe</LastName>
<Amount>1.00</Amount>
<LastFour>1111</LastFour>
<CardType>Visa</CardType>
<TranDate>02/16/2014</Tran Date>
<TranTime>11:13:07</TranTi me>
<Status>Settled</Status>
</Row>
</QueryResponse>
How I will I save it to a xml file. How will I achieve this ?? Please help me
from the method I am getting xml string like this and I want to Keep inside "<Response>" how will I do that.
string clResponse = EncryptDecrypt.DecryptStri
I am getting xml string like this
<Reference>
<Guid>3TKYN2H3FKN501J</Gui
<TranDate>04/11/2014</Tran
<TranTime>12:18:58</TranTi
</Reference>
<Result>
<ResponseCode>00</Response
<ResponseText>Query Complete</ResponseText>
</Result>
<QueryResponse>
<Row>
<Client>177</Client>
<Dba>Tarang</Dba>
<Guid>3P9JFLVNFL4VMXN</Gui
<TranType>Credit</TranType
<TranAction>Sale</TranActi
<ResponseCode>00</Response
<ResponseText>Approved</Re
<FirstName>John</FirstName
<LastName>Doe</LastName>
<Amount>1.00</Amount>
<LastFour>1111</LastFour>
<CardType>Visa</CardType>
<TranDate>02/16/2014</Tran
<TranTime>11:13:07</TranTi
<Status>Settled</Status>
</Row>
</QueryResponse>
How I will I save it to a xml file. How will I achieve this ?? Please help me
Hi TAPAN;
The XML that you posted has no node with the name Response and also has no root node. Which part do you want to get?
The XML that you posted has no node with the name Response and also has no root node. Which part do you want to get?
ASKER
How will I add Root node as "<Response>" in the above xml string which I am receiving from the client and I want to save the above xml file. File should be like this.
<Response>
<Reference>......</Referen ce>
<Result>......</Result>
<QueryResponse>.........</ QueryRespo nse>
</Response>
<Response>
<Reference>......</Referen
<Result>......</Result>
<QueryResponse>.........</
</Response>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much
check at the "Generate a XML output" section from http://emoreau.com/Entries/Articles/2009/04/Using-LINQ-and-XML-Literals-to-transform-a-DataTable-into-a-HTML-table.aspx