We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15175
    • 116 Posts
    I need to generate a simple XML file via Ditto.

    I have created a new document set to use a blank template with content type set to text/xml, with rich text turned off.

    This is the Document content:

    <?xml version="1.0" encoding="utf-8"?>
    <root>
    [!Ditto? &parents=`38` &format=`xml` &tpl=`iphone-feed-tpl`!]
    </root>


    This is the tpl:

    <news date="[+createdon:date=`%d.%m.%y %H:%M`+]">
    <title>[+pagetitle+]</title>
    <body>[+main-text+]</body>
    <image ThumbImage="[(site_url)][+small-image+]" bigImage="[(site_url)][+large-image+]"/>
    </news>


    As far as i understand it, if I specify a tpl, then xml.format.inc.php is not used, but I am still getting the header and footer information from there within my generated XML:

    <?xml version="1.0" encoding="utf-8"?>
    <root>
    <?xml version="1.0" encoding="" ?>
    
    <xml version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    		<channel>
    				<title>iphone-feed</title>
    				<link></link>
    				<description></description>
    				<language></language>
    				<copyright></copyright>
    
    				<ttl></ttl>
    <news date="25.07.09 17:25">
    <title>News item 1</title>
    
    etc....
    
    </news>
    
    
    		</channel>
    </xml>
    </root>


    What am I doing wrong?

      • 33337
      • 3,975 Posts
      Ditto adds XML declarations automatically, so its getting duplicated. Try removing your own xml declaration and see if it helps.
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 15175
        • 116 Posts
        Thanks for replying zi.

        After removing my declaration in the Document content, the top of my XML file now looks like this:

        <root>
        <?xml version="1.0" encoding="" ?>
        
        <xml version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
        		<channel>
        				<title>iphone-feed.xml</title>
        				<link></link>
        				<description></description>
        				<language></language>
        				<copyright></copyright>
        
        				<ttl></ttl><news date="25.07.09 17:25">
        <title>News item 1</title>
        


        <root> should be immediately before <title>, not at the top before the declaration(s), and I want to remove all the other output that has been generated. I have managed to get the output I want by commenting out the header and footer in xml.format.inc.php, but surely this isn’t the proper way of doing it?

        Also, the site is on Windows hosting - I don’t know if this would cause any issues.
          • 10449
          • 956 Posts
          you can simply remove &format=`xml` altogether from your Ditto-call.
            • 15175
            • 116 Posts
            Excellent, thank you very much ganeshXL.
              • 33337
              • 3,975 Posts
              Quote from: ganeshXL at Jul 26, 2009, 01:03 PM

              you can simply remove &format=`xml` altogether from your Ditto-call.

              Clever! wink
                Zaigham R - MODX Professional | Skype | Email | Twitter

                Digging the interwebs for #MODX gems and bringing it to you. modx.link