Need some help with XML composition.
Posted: Thu Jun 28, 2007 7:31 pm
I just dont get why this does't work...
XMLStory is a subset of XMLBlog. XMLStory has two children, story_teaser, and story_body.
I have a handful of other tags in the XML document...but for some reason $XMLStoryBody->appendChild( $dom->createTextNode($story) ); does not work.
If I put something directly in quotes into the createTextNode function, it will show up in the xml file I save. But not if I use the $story variable. I see the tags <story_body></story_body> in the XML file, but no text. Please help
XMLStory is a subset of XMLBlog. XMLStory has two children, story_teaser, and story_body.
I have a handful of other tags in the XML document...but for some reason $XMLStoryBody->appendChild( $dom->createTextNode($story) ); does not work.
If I put something directly in quotes into the createTextNode function, it will show up in the xml file I save. But not if I use the $story variable. I see the tags <story_body></story_body> in the XML file, but no text. Please help
Code: Select all
//STORY//
$XMLStory = $XMLBlog->appendChild($dom->createElement('story'));
$XMLTeaser = $XMLStory->appendChild($dom->createElement('story_teaser'));
$XMLTeaser->appendChild( $dom->createTextNode($teaser) );
echo "<P>#####################<P>STORY:<P>$story<P>$$$$$$$$<P>";
$XMLStoryBody = $XMLStory->appendChild($dom->createElement('story_body'));
$XMLStoryBody->appendChild( $dom->createTextNode($story) );
//Get the content
$story = $_POST['story'];
$title = $_POST['title'];
$subject = $_POST['subject'];
$teaser = $_POST['teaser'];
$author = $_POST['author'];
$story = str_replace( "\n","<P>",$story);
echo "HELLO WORLD<P>";
echo "<P>Thank you for submitting your article.<P>";
echo "<P>You submitted:<BR>";
echo "<B>$title</B><BR><I>$author</I><BR>$story</P>";
//DO TITLE
if (strlen($title) <1 )
die ("Need title");
$title = stripslashes($title);
$title = ereg_replace("[^[]+^\ ]", "", $title); //Replace non alpha |^[' ']
$filename = str_replace( ' ', '_', $title);
$title = CleanTags($title);
$filename =CleanTags($filename);
echo "<P>Your file is saved as $filename</P>";
//TEASER
if( strlen($teaser)<1)
{
//No teaser, get first 100 words from story.
$storyTemp = $story;
$storyTemp = CleanTags($storyTemp);
$storyTemp = stripslashes($storyTemp);
$start = 0; $end = 0;
$fstr = "."; $ctr = 0; $loc = 0;
//Get the first x sentances of the story based on teaser sentence count
while ( $ctr < TEASER_SEN_COUNT /*and $loc < strlen($Story) */)
{
$loc = strpos( $storyTemp, $fstr, $loc+1 );
$ctr++;
}
echo "\n";echo "LOC: "; echo $loc; echo "\n";
//Get the teaser up to where the last counter loc was. T_W_C words or less.
$teaser = substr($storyTemp, 1, $loc);
}//TEASER DONE
/***********************
** DOM FOR BLOGS
** <Blog>
** <Title />
** <Subject />
** <Author />
** <Teaser />
** <Gen-Info>
** <Hits />
** <Story />
**<Comment sheet />
***************************/
//Creates XML string and XML document using the DOM
$dom = new DomDocument('1.0');
//Blog and sub cat info
$XMLBlog = $dom->appendChild($dom->createElement('blog'));
$XMLInfo = $XMLBlog->appendChild($dom->createElement('info'));
//Information elements
//Add title element to blog
$XMLTitle = $XMLInfo->appendChild($dom->createElement('info_title'));
$XMLTitle->appendChild( $dom->createTextNode($title) );
$XMLAuthor = $XMLInfo->appendChild($dom->createElement('info_author'));
$XMLAuthor->appendChild( $dom->createTextNode($author) );
$XMLFilename = $XMLInfo->appendChild($dom->createElement('info_filename'));
$XMLFilename->appendChild( $dom->createTextNode($filename) );
////
//STORY//
$XMLStory = $XMLBlog->appendChild($dom->createElement('story'));
$XMLTeaser = $XMLStory->appendChild($dom->createElement('story_teaser'));
$XMLTeaser->appendChild( $dom->createTextNode($teaser) );
echo "<P>#####################<P>STORY:<P>$story<P>$$$$$$$$<P>";
$XMLStoryBody = $XMLStory->appendChild($dom->createElement('story_body'));
$XMLStoryBody->appendChild( $dom->createTextNode($story) );