1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Creating an XML file based off of database

Discussion in 'XenForo Development Discussions' started by Jeremy, Nov 24, 2010.

  1. Jeremy

    Jeremy XenForo Moderator Staff Member

    OK, I'm working on the next version of BBCM and I am currently fighting with an XML output. Here's my issue:

    The code that I wrote, based off of XenForo's export add-on code and checked against XenPorta, doesn't create a proper XML output. Every time I go to the page to view it... I get a "The requested page is unrepresentable as XML." error. Here's my code:
    PHP:
        public function getBbCodeXml(array $bbcode)
        {
            
    $document = new DOMDocument('1.0''utf-8');
            
    $document->formatOutput true;

            
    $rootNode $document->createElement('bbcode');
            
    $document->appendChild($rootNode);

            
    $rootNode->appendChild($document->createElement('tag'$bbcode['tag']));
            
    $rootNode->appendChild($document->createElement('title'$bbcode['title']));
            
    $rootNode->appendChild($document->createElement('description'$bbcode['description']));

            
    $replacement $rootNode->appendChild($document->createElement('replacement'));
            
    $replacement->appendChild($document->createElement('begin'$bbcode['replacementBegin']));
            
    $replacement->appendChild($document->createElement('end'$bbcode['replacementEnd']));

            
    $phpcallback $rootNode->appendChild($document->createElement('phpcallback'));
            
    $phpcallback->appendChild($document->createElement('class'$bbcode['phpcallback_class']));
            
    $phpcallback->appendChild($document->createElement('method'$bbcode['phpcallback_method']));
            
    $rootNode->appendChild($document->createElement('example'$bbcode['example']));
            
    $rootNode->appendChild($document->createElement('active'$bbcode['active']));
            
    $rootNode->appendChild($document->createElement('requiresOption'$bbcode['requiresOption']));
            
    $rootNode->appendChild($document->createElement('advancedOptions'$bbcode['advancedOptions']));
            
    $rootNode->appendChild($document->createElement('numberOfOptions'$bbcode['numberOfOptions']));
            
    $rootNode->appendChild($document->createElement('regex'$bbcode['regex']));
            
    $rootNode->appendChild($document->createElement('trimLeadingLinesAfter'$bbcode['trimLeadingLinesAfter']));
            
    $rootNode->appendChild($document->createElement('plainCallback'$bbcode['plainCallback']));
            
    $rootNode->appendChild($document->createElement('plainChildren'$bbcode['plainChildren']));
            
    $rootNode->appendChild($document->createElement('stopSmilies'$bbcode['stopSmilies']));
            
    $rootNode->appendChild($document->createElement('stopLineBreakConversion'$bbcode['stopLineBreakConversion']));

            
    XenForo_Application::autoload('Zend_Debug');
            
    Zend_Debug::dump($document);
            return 
    $document;
        }
    I have no idea why to do here... Thoughts?

    Edit: I modified the replacementEnd / replacementBegin to be CDATA sections because they contain HTML, but it still fails. Here's what my current code is:
    PHP:
        public function getBbCodeXml(array $bbcode)
        {
            
    $document = new DOMDocument('1.0''utf-8');
            
    $document->formatOutput true;

            
    $rootNode $document->createElement('bbcode');
            
    $document->appendChild($rootNode);

            
    $rootNode->appendChild($document->createElement('tag'$bbcode['tag']));
            
    $rootNode->appendChild($document->createElement('title'$bbcode['title']));
            
    $rootNode->appendChild($document->createElement('description'$bbcode['description']));

            
    $replacement $rootNode->appendChild($document->createElement('replacement'));
            
    $replacementBegin $replacement->appendChild($document->createElement('begin'''));
            
    $replacementBegin->appendChild($document->createCDATASection($bbcode['replacementBegin']));
            
    $replacementEnd $replacement->appendChild($document->createElement('end'''));
            
    $replacementEnd->appendChild($document->createCDATASection($bbcode['replacementEnd']));

            
    $phpcallback $rootNode->appendChild($document->createElement('phpcallback'));
            
    $phpcallback->appendChild($document->createElement('class'$bbcode['phpcallback_class']));
            
    $phpcallback->appendChild($document->createElement('method'$bbcode['phpcallback_method']));
            
    $rootNode->appendChild($document->createElement('example'$bbcode['example']));
            
    $rootNode->appendChild($document->createElement('active'$bbcode['active']));
            
    $rootNode->appendChild($document->createElement('requiresOption'$bbcode['requiresOption']));
            
    $rootNode->appendChild($document->createElement('advancedOptions'$bbcode['advancedOptions']));
            
    $rootNode->appendChild($document->createElement('numberOfOptions'$bbcode['numberOfOptions']));
            
    $rootNode->appendChild($document->createElement('regex'$bbcode['regex']));
            
    $rootNode->appendChild($document->createElement('trimLeadingLinesAfter'$bbcode['trimLeadingLinesAfter']));
            
    $rootNode->appendChild($document->createElement('plainCallback'$bbcode['plainCallback']));
            
    $rootNode->appendChild($document->createElement('plainChildren'$bbcode['plainChildren']));
            
    $rootNode->appendChild($document->createElement('stopSmilies'$bbcode['stopSmilies']));
            
    $rootNode->appendChild($document->createElement('stopLineBreakConversion'$bbcode['stopLineBreakConversion']));

        
    //    XenForo_Application::autoload('Zend_Debug');
        //    Zend_Debug::dump($document);
            
    return $document;
        }
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    Actually, this works. If I do $document->save('filename.xml'); it provides a valid file in the specified path. Its getting it to display / download to the browser that's my problem. D0es it matter if there are [] within a CDATA tag?

    Here's that file:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <bbcode>
      <tag>h2</tag>
      <title>H2</title>
      <description>Adds a H2 tag around the contained text.</description>
      <replacement>
        <begin><![CDATA[<h2>]]></begin>
        <end><![CDATA[</h2>]]></end>
      </replacement>
      <phpcallback>
        <class></class>
        <method></method>
      </phpcallback>
      <example><![CDATA[[h2]Header Tag[/h2]]]></example>
      <active>1</active>
      <requiresOption>0</requiresOption>
      <advancedOptions>0</advancedOptions>
      <numberOfOptions>0</numberOfOptions>
      <regex></regex>
      <trimLeadingLinesAfter>0</trimLeadingLinesAfter>
      <plainCallback>0</plainCallback>
      <plainChildren>0</plainChildren>
      <stopSmilies>0</stopSmilies>
      <stopLineBreakConversion>0</stopLineBreakConversion>
    </bbcode>
    
     
  3. Jeremy

    Jeremy XenForo Moderator Staff Member

    And.... don't ask me what I did, but it is now working flawlessly... *sigh* I think my class may have been wrong for my ViewAdmin, but I'm not entirely sure...
     
  4. Jaxel

    Jaxel Well-Known Member

    You coulda just asked me... since you were using my mod as an example... You need a proper View class
    Code:
    <?php
    
    class EWRporta_ViewPublic_Export extends XenForo_ViewPublic_Base
    {
    	public function renderXml()
    	{
    		$this->setDownloadFileName($this->_params['module']['module_name'] . '.xml');
    		return $this->_params['xml']->saveXml();
    	}
    }
     
    Mythotical likes this.
  5. Jeremy

    Jeremy XenForo Moderator Staff Member

    I had one of those... That's the weird part. I am completely lost as to why it was occurring as it was.
     
    pegasus likes this.
  6. pegasus

    pegasus Well-Known Member

    Thanks, this was driving me nuts. I feel like there should be a default XML renderer that you can send an 'xml' param to and it just outputs the XML. It feels like a waste having this as a class:
    Code:
    <?php
     
    class myProduct_ViewPublic extends XenForo_ViewPublic_Base
    {
    	public function renderXml()
    	{
    		return $this->_params['xml']->saveXML();
    	}
    }
     

Share This Page