Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I generate this XML page dynamically in C# / ASP.NET MVC?
    primarykey
    data
    text
    <p>I'm trying to create an XML file to conform to Indeed.com's Job Listing XML.</p> <p>It looks like:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;source&gt; &lt;publisher&gt;Super X Job Site&lt;/publisher&gt; &lt;publisherurl&gt;http://www.superxjobsite.com&lt;/publisherurl&gt; &lt;job&gt; &lt;title&gt;&lt;![CDATA[Sales Executive]]&gt;&lt;/title&gt; &lt;date&gt;&lt;![CDATA[Fri, 10 Dec 2005 22:49:39 GMT]]&gt;&lt;/date&gt; &lt;referencenumber&gt;&lt;![CDATA[unique123131]]&gt;&lt;/referencenumber&gt; &lt;url&gt;&lt;![CDATA[http://www.superxjobsite.com/job/123]]&gt;&lt;/url&gt; &lt;company&gt;&lt;![CDATA[Big ABC Corporation]]&gt;&lt;/company&gt; &lt;city&gt;&lt;![CDATA[Phoenix]]&gt;&lt;/city&gt; &lt;state&gt;&lt;![CDATA[AZ]]&gt;&lt;/state&gt; &lt;country&gt;&lt;![CDATA[US]]&gt;&lt;/country&gt; &lt;postalcode&gt;&lt;![CDATA[85003]]&gt;&lt;/postalcode&gt; &lt;description&gt;&lt;![CDATA[Some really long job description goes here.]]&gt;&lt;/description&gt; &lt;/job&gt; [ more jobs ...] </code></pre> <p></p> <p>Now, right now I have a IEnumberable of "Jobs", which has properties which match each one of the XML elements above.</p> <p>What is the best way to generate this XML document and return it as an ActionResult in ASP.NET MVC?</p> <p>One way, is I could construct the XML string manually like:</p> <pre><code>String xmlDoc = "&lt;?xml version="1.0" encoding="utf-8"?&gt;"; xmlDoc += "&lt;source&gt;"; xmlDoc += "&lt;publisher&gt;Super X Job Site&lt;/publisher&gt;"; xmlDoc += "&lt;publisherurl&gt;http://www.superxjobsite.com&lt;/publisherurl&gt;"; foreach(Job job in Jobs) { xmlDoc += "&lt;job&gt;"; xmlDoc += "&lt;description&gt;" + job.Description + "&lt;/description&gt;"; ... } </code></pre> <p>While I know this method would work, is there a better way I should be doing this so I can generate this XML?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload