locked
accept a xml in web api RRS feed

  • Question

  • User-732838899 posted

    Hi all, 

    I have a xml file like belowm 

    <?xml version="1.0" encoding="UTF-8"?>

    <bookstore>

      <book category="cooking">

        <title lang="en">Everyday Italian</title>
        <author>Giada De Laurentiis</author>
        <year>2005</year>
        <price>30.00</price>
      </book>

    </bookstore>

    and i wanted to create a web api end point to accept the above xml and save it in a local drive as a xml file.   also if i can do some validation on xml beofore I accept this in web api side that would be really great, 

    could some one direct me in to the right approach to do this ? 

    thanks

    Tuesday, February 9, 2016 11:11 AM

Answers

  • User-84896714 posted

    Hi kavithma,

    to accept the above xml and save it in a local drive as a xml file.

    We could accept string value and parse it to xml.

    XDocument xml = XDocument.Parse(text);

    also if i can do some validation on xml beofore I accept this in web api side that would be really great, 

    Use custom validation to validate it.
    http://www.asp.net/web-api/videos/getting-started/custom-validation

    Best Regards,
    Li Wang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 9, 2016 3:29 PM