I have created a function that creates .xml files from input from a form provided in another script and saves the file in a network location. I got this working correctly, however, when i tried to convert it into a wordpress plugin (creating the .xml file from post meta data upon publishing) i can't get it to work...

if(!wp_is_post_revision($post->ID) && $post->post_type == 'friendly') {
 add_action('publish_post','whatever');
 }
    function whatever($postid) {
// $postid has the post id in it.

// The Query
$the_query = new WP_Query( 'p='.$postid );

// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();

$client = the_title();
$value = get_post_meta($post->ID, 'my_meta_box_text', TRUE);
$niceAnchors= '';
$copy_title1 = get_post_meta($post->ID, 'my_meta_box_text_title', TRUE);
$copy_title2 = get_post_meta($post->ID, 'my_meta_box_text_title', TRUE);
$postText = get_post_meta($post->ID, 'my_meta_box_textarea_copy', TRUE);


$doc = new DOMDocument();       

     // specify the version and encoding
     $doc->version = '1.0';
     $doc->encoding = 'UTF-8';

      // Create a comment
      $comment = $doc->createComment('Create the .xml Project file for.');
      // Put this comment at the Root of the XML doc
     $doc->appendChild($comment);

      // Create an Empty element 'note'
      $note = $doc->createElement('Project');
      // Create an Empty element 'PrimarySection'
      $PrimarySection = $doc->createElement('PrimarySection');
      // Put the 'note' element at the Root of the XML doc (just after the comment)
      $doc->appendChild($note);
      $note->appendChild($PrimarySection);

          // Create main elements
          $ProjectName      = $doc->createElement('ProjectName', 'p1A_'.$client.'_'.$i);
          $NickName    = $doc->createElement('NickName', '#random[a..z]#random[a..z]hare#random[a..z]#random[1..9]');
          $RealName = $doc->createElement('RealName', '#random[a..z]#random[a..z]hare#random[a..z]#random[1..9]');
          $Password    = $doc->createElement('Password', '#random[a..z]#random[1..9]#random[a..z]#random[a..z]#random[1..9]#random[a..z]#random[a..z]#random1..9]#random[a..z]#random[a..z]');
          $EmailAddress      = $doc->createElement('EmailAddress', '#file_links[C:\Lists\EmailList.txt,1,L]');   
          $EmailPassword      = $doc->createElement('EmailPassword', '1'); 
          $EmailLogin      = $doc->createElement('EmailLogin', '#'); 
          $EmailPOP      = $doc->createElement('EmailPOP', '#'); 
          $Homepage      = $doc->createElement('Homepage', $value); 
          $ICQ      = $doc->createElement('ICQ', '#random[1..9]#random[1..9]#random[1..9]#random[1..9]#random[1..9]#random[1..9]#random[1..9]#random[1..9]#random[1..9]'); 
          $City      = $doc->createElement('City', '#file_links[C:\Lists\CityList.txt,1,L]'); 
          $Country      = $doc->createElement('Country', '#file_links[C:\Lists\CountryList.txt,1,L]'); 
          $Occupation      = $doc->createElement('Occupation', '#file_links[C:\Lists\occupations.txt,1,L]'); 
          $Interests      = $doc->createElement('Interests', '#file_links[C:\Lists\hobbieslist.txt,1,L]'); 
          $Signature      = $doc->createElement('Signature', $niceAnchors); 
          $Gender      = $doc->createElement('Gender', '0'); 
          $UnknownFields      = $doc->createElement('UnknownFields', ''); 
          $PollTitle      = $doc->createElement('PollTitle', ''); 
          $PollOption1      = $doc->createElement('PollOption1', ''); 
          $PollOption2      = $doc->createElement('PollOption2', ''); 
          $PollOption3      = $doc->createElement('PollOption3', ''); 
          $PollOption4      = $doc->createElement('PollOption4', ''); 
          $PollOption5      = $doc->createElement('PollOption5', ''); 

      // Specify that those newly created elements are 'note' children
        $PrimarySection->appendChild($ProjectName);
        $PrimarySection->appendChild($NickName);
        $PrimarySection->appendChild($RealName);
        $PrimarySection->appendChild($Password);
        $PrimarySection->appendChild($EmailAddress);
        $PrimarySection->appendChild($EmailPassword);   
        $PrimarySection->appendChild($EmailLogin);
        $PrimarySection->appendChild($EmailPOP);
        $PrimarySection->appendChild($Homepage);
        $PrimarySection->appendChild($ICQ);
        $PrimarySection->appendChild($City);
        $PrimarySection->appendChild($Country); 
        $PrimarySection->appendChild($Occupation);
        $PrimarySection->appendChild($Interests);
        $PrimarySection->appendChild($Signature);
        $PrimarySection->appendChild($Gender);
        $PrimarySection->appendChild($UnknownFields);
        $PrimarySection->appendChild($PollTitle);
        $PrimarySection->appendChild($PollOption1);
        $PrimarySection->appendChild($PollOption2);
        $PrimarySection->appendChild($PollOption3);
        $PrimarySection->appendChild($PollOption4);
        $PrimarySection->appendChild($PollOption5);

        //create Secondary Section
        $SecondarySection = $doc->createElement('SecondarySection');
        $note->appendChild($SecondarySection);

        $Subject1 = $doc->createElement('Subject1', $copy_title1);
        $Subject2 = $doc->createElement('Subject2', $copy_title2);
        $PostText = $doc->createElement('PostText', $postText);
        $Prior = $doc->createElement('Prior', '');
        $OnlyPriors = $doc->createElement('OnlyPriors', '');    

        $SecondarySection->appendChild($Subject1);
        $SecondarySection->appendChild($Subject2);
        $SecondarySection->appendChild($PostText);
        $SecondarySection->appendChild($Prior);
        $SecondarySection->appendChild($OnlyPriors);

            // Beautify
            $doc->formatOutput = true;

            // Save this
            $doc->save('/saved/'.$client.'_'.$postid.'xml');

    // Reset Post Data
    wp_reset_postdata();
    endwhile;
 }

so my question is, what do i need to do to make wordpress create the .xml file when the post is published with meta data as variables inside the create .xml script?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.