0

Hi I'm working on Developing a Web-API project, which connects and working with multi-devices. I have one requirement like print XML format directly in mobile print device(WizarPOS), i need to send response format as given below.

<RESPONSE TYPE="PRINT" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<TERMINALID>993324</TERMINALID>
<LOCALDATETIME>2018-11-16 09:08:40</LOCALDATETIME>
<SERVERDATETIME>6/29/2018 3:33:34 PM</SERVERDATETIME>
<TXID>880034435</TXID>
<HOSTTXID>ID00008769249</HOSTTXID>
<AMOUNT>500</AMOUNT>
<CURRENCY>634</CURRENCY>
<LIMIT>0</LIMIT>
<RECEIPT>
    <LINES>14</LINES>
    <LINE>Provider Pin</LINE>
    <LINE>TerminalID:                                 993324</LINE>
    <LINE>Date:                                   29.06.2018</LINE>
    <LINE>TimeOfDay:                                15:06:SS</LINE>
    <LINE>Trace-No:                                   160537</LINE>
    <LINE>Receipt-No:                                 475514</LINE>
    <LINE>--------------------------------------------------</LINE>
    <LINE>Value:                                     500 QAR</LINE>
    <LINE>Product without VAT</LINE>
    <LINE>Service:                                7736737741</LINE>
    <LINE>Hotline:                               0110/400773</LINE>
    <LINE>Serial Number:                           778617719</LINE>
    <LINE>CashCode:</LINE>
    <LINE>2866-8195-3923-8894</LINE>
</RECEIPT>
<RESULT>0</RESULT>
<RESULTTEXT>Transaction Successful</RESULTTEXT>
<PINCREDENTIALS>
    <PIN>2846-4607-1987-3562</PIN>
    <SERIAL>778617719</SERIAL>
    <VALIDTO>11/29/2018 3:33:34 PM</VALIDTO>
</PINCREDENTIALS>

For this i have created two one main class and two nested class, one nested class with list of string derived class as shown below

[XmlRoot("RESPONSE", DataType = "PRINT")]
public class PinDirectResponseVM
{
    public int TERMINALID { get; set; }
    public string LOCALDATETIME { get; set; }
    public string SERVERDATETIME { get; set; }
    public int TXID { get; set; }
    public string HOSTTXID { get; set; }
    public string AMOUNT { get; set; }
    public string CURRENCY { get; set; }
    public string LIMIT { get; set; }
    [XmlArrayItem(ElementName = "LINE")]
    public ReceiptResponseVM RECEIPT { get; set; }
    public string RESULT { get; set; }
    public string RESULTTEXT { get; set; }
    public string AID { get; set; }
    public PinCredentialsResponseVM PINCREDENTIALS { get; set; }
}
public class ReceiptResponseVM : List<string>
{
    public int LINES { get; set; }
}
public class PinCredentialsResponseVM
{
    public string PIN { get; set; }
    public string SERIAL { get; set; }
    public string VALIDTO { get; set; }
}

When i returning 'PinDirectResponseVM' object not getting <LINES>14<LINES> tag,i getting response like this

<RESPONSE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<TERMINALID>993324</TERMINALID>
<LOCALDATETIME>2018-11-16 09:08:40</LOCALDATETIME>
<SERVERDATETIME>6/29/2018 3:33:34 PM</SERVERDATETIME>
<TXID>880034435</TXID>
<HOSTTXID>ID00008769249</HOSTTXID>
<AMOUNT>500</AMOUNT>
<CURRENCY>634</CURRENCY>
<LIMIT>0</LIMIT>
<RECEIPT>
    <LINE>Provider Pin</LINE>
    <LINE>TerminalID:                                 993324</LINE>
    <LINE>Date:                                   29.06.2018</LINE>
    <LINE>TimeOfDay:                                15:06:SS</LINE>
    <LINE>Trace-No:                                   160537</LINE>
    <LINE>Receipt-No:                                 475514</LINE>
    <LINE>--------------------------------------------------</LINE>
    <LINE>Value:                                     500 QAR</LINE>
    <LINE>Product without VAT</LINE>
    <LINE>Service:                                7736737741</LINE>
    <LINE>Hotline:                               0110/400773</LINE>
    <LINE>Serial Number:                           778617719</LINE>
    <LINE>CashCode:</LINE>
    <LINE>2866-8195-3923-8894</LINE>
</RECEIPT>
<RESULT>0</RESULT>
<RESULTTEXT>Transaction Successful</RESULTTEXT>
<PINCREDENTIALS>
    <PIN>2846-4607-1987-3562</PIN>
    <SERIAL>778617719</SERIAL>
    <VALIDTO>11/29/2018 3:33:34 PM</VALIDTO>
</PINCREDENTIALS>

So please help me to get the response as per my requirement, what's the best way to generate XML for it?

1 Answer 1

1

This is because there are two different child nodes in <RECEIPT></RECEIPT> node which are

<LINES></LINES>
<LINE></LINE>

You can do something like this:

    XmlRoot("RESPONSE", DataType = "PRINT")]
    public class PinDirectResponseVM
    {
        public int TERMINALID { get; set; }
        public string LOCALDATETIME { get; set; }
        public string SERVERDATETIME { get; set; }
        public int TXID { get; set; }
        public string HOSTTXID { get; set; }
        public string AMOUNT { get; set; }
        public string CURRENCY { get; set; }
        public string LIMIT { get; set; }

        public ReceiptResponseVM RECEIPT { get; set; }
        public string RESULT { get; set; }
        public string RESULTTEXT { get; set; }
        public string AID { get; set; }
        public PinCredentialsResponseVM PINCREDENTIALS { get; set; }
    }
    public class ReceiptResponseVM //: List<string>
    { 
        [XmlElement(Order = 1, ElementName = "LINES")]
        public int LINES { get; set; }

        [XmlElement(Order = 2, ElementName = "LINE")]
        public List<string> LINE {get; set;}
    }
    public class PinCredentialsResponseVM
    {
        public string PIN { get; set; }
        public string SERIAL { get; set; }
        public string VALIDTO { get; set; }

}
Sign up to request clarification or add additional context in comments.

4 Comments

Hi Sahil, Thanks you, for spending valuable time for this, but in this i'm not able to see order param in xmlarray item,is required any library or dll for that
If you check without the order parameter, is it working?
No it's not working same result as i mentioned in question only getting..
Updated the answer with XmlElement attribute. Check now

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.