0

Can someone please help me with the following problem. I want to create a xml that have namespaces and attributes with C# model class

In present, I create a string like this:

var xmlFile =
@"<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>
    <s:Body>
        <GetAllowedCategoryTree xmlns='http://www.cdiscount.com'>
            <headerMessage xmlns:a='http://schemas.datacontract.org/2004/07/Cdiscount.Framework.Core.Communication.Messages' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
                <a:Context>
                    <a:SiteID>100</a:SiteID>
                </a:Context>
                <a:Localization>
                    <a:Country>Fr</a:Country>
                    <a:Currency>Eur</a:Currency>
                    <a:DecimalPosition>2</a:DecimalPosition>
                    <a:Language>Fr</a:Language>
                </a:Localization>
                <a:Security>
                    <a:DomainRightsList i:nil='true' />
                    <a:IssuerID i:nil='true' />
                    <a:SessionID i:nil='true' />
                    <a:SubjectLocality i:nil='true' />
                    <a:TokenId>" + token + @"</a:TokenId>
                    <a:UserName i:nil='true' />
                </a:Security>
                <a:Version>1.0</a:Version>
            </headerMessage>
        </GetAllowedCategoryTree>
    </s:Body>
</s:Envelope>";

But I want to work with object, because it's easier.

The only field that is changing is tokenId, this is also the field that I want to set.

I don't know how to make a class that have an xml element like <s:Envelope xmlns:s='...'>

Thanks a lot for your attention!

Jackdaw
  • 7,626
  • 5
  • 15
  • 33
  • Can you be more specific? So .. do you want a class to model this xml file? Or do you want to get the value of TokenId from the xml file? Or set the value of TokenId in the xml? – marsze Oct 15 '21 at 18:46
  • Does this answer your question? [Convert XML String to Object](https://stackoverflow.com/questions/3187444/convert-xml-string-to-object) – Vivek Nuna Oct 15 '21 at 18:53
  • I want to create a C# model class based on that xml, and the only field that i want to set is TokenId, cause that field is different, the others (CatalogID, Currency, etc) are the same everytime. – Daniel Onica Oct 15 '21 at 19:07
  • Why are you not using any proxy generated for service ? Like you add reference and proxy class generated for you and if you want to keep xml way then use XElement or so to manuplate it. – dotnetstep Oct 16 '21 at 05:53

0 Answers0