Jump to content

parsing problem


jenni_fur

Recommended Posts

hey, i actually have a number of problem with a project i'm working on but at the moment this is the most frustrating.

Two problems, firstly if I input over 1000 charasters to my xml file, in any particular field, it crashes! and secondly when i use anything like <>/""'' it crashes too! my attempt at using CDATA! scritp thus far has been unsuccessful and i woud be greatful for some input....!

this is the parser
[!--sizeo:1--][span style=\"font-size:8pt;line-height:100%\"][!--/sizeo--]
[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]EDIT-Zanus: Put code, especially long code into the code tag
to make it easier for people to read please[!--colorc--][/span][!--/colorc--][!--sizec--][/span][!--/sizec--]
[code]<?php

if( ! ($fp = fopen( "./home.xml" , "r" )) )
  die("Couldn't open xml file!");
$person_counter_home = 0;
$person_data_home = array();
$xml_current_tag_state_home = '';
function startElementHandlerHome( $parser_home, $element_name_home, $element_attribs_home )
{
  global $person_counter_home;
  global $person_data_home;
  global $xml_current_tag_state_home;
  if( $element_name_home == "STORY" )
  {
   // $person_data_home[$person_counter_home]["author"] = $element_attribs_home["AUTHOR"];
  }
  else
  {
    $xml_current_tag_state_home = $element_name_home;
  }
}
function endElementHandlerHome( $parser_home, $element_name_home )
{
  global $person_counter_home;
  global $person_data_home;
  global $xml_current_tag_state_home;
  $xml_current_tag_state_home = '';
  if( $element_name_home == "STORY" )
  {
    $person_counter_home++;
  }
}
function characterDataHandlerHome( $parser_home , $data_home )
{
  global $person_counter_home;
  global $person_data_home;
  global $xml_current_tag_state_home;
  if( $xml_current_tag_state_home == '' )
    return;
if( $xml_current_tag_state_home == "HOMEPAGE" ) {
    $person_data_home[$person_counter_home]["homepage"] = $data_home;
  }    
    
  if( $xml_current_tag_state_home == "WELCOME" ) {
    $person_data_home[$person_counter_home]["welcome"] = $data_home;
  }
  if( $xml_current_tag_state_home == "MAIN" ) {
    $person_data_home[$person_counter_home]["main"] = $data_home;
    
  }
  if( $xml_current_tag_state_home == "NEWINFO" ) {
    $person_data_home[$person_counter_home]["newinfo"] = $data_home;
    
  }
  if( $xml_current_tag_state_home == "IMAGE" ) {
    $person_data_home[$person_counter_home]["image"] = $data_home;
  }
  if( $xml_current_tag_state_home == "ALT" ) {
    $person_data_home[$person_counter_home]["alt"] = $data_home;
  }
  
}
if( !($xml_parser_home = xml_parser_create()) )
  die("Couldn't create XML parser!");

xml_set_element_handler($xml_parser_home, "startElementHandlerHome", "endElementHandlerHome");
xml_set_character_data_handler($xml_parser_home, "characterDataHandlerHome");
while( $data_home = fread($fp, 4096) )
{
  if( !xml_parse($xml_parser_home, $data_home, feof($fp)) )
  {
    break; // get out of while loop if we're done with the file
  }
}
xml_parser_free($xml_parser_home);



?>
<?php

$article = $homepageContent;
$thisPos_home = -1;
$lengthOfArrayHome = count($person_data_home);

for( $i=0; $i < $lengthOfArrayHome; ++$i )
{
$thisName_home = $person_data_home[$i]["homepage"];
//echo $thisName_home. "<br>";

if ($thisName_home == $article) {

$thisPos_home = $i;
}

}


//unset($person_data_home[$thisPos_home]);
$elementPos_home = 0;

if ($thisPos_home==-1)
{

$elementPos_home = $lengthOfArrayHome;

}
else
{

$elementPos_home = $thisPos_home;

}

?>[/code]
Link to comment
Share on other sites

yeah, i dont think i explained myself very well. Sorry

i have built a content management system to edit and update a site i'm working on, however if i input over 1000 characters into any particular field, it will only display the amout of characters in excess of the 1000 character limit.

At first i thought this was a simple html css problem, however on closer inspection, when i upload new info to the xmi via my content management system, it does actually work, however once i view it on the public site, only the excess characters show.

would it help if i posted the code that is supposed to print the content from the XML?? this is it below
[code]
<?php
include "./homeparser.inc";

?>

<?php
include "./homearray.inc";
?>
<div id="home">
<?php

echo "<h1>";
for( $i=0; $i < $lengthOfArrayHome; ++$i )
{
$thisNameHome = $person_data_home[$i]["welcome"];

echo $welcomeContent=$thisNameHome."<br>";
}
echo "<br>";
echo "whats new..";
echo "</h1>";
?>
  
<?php
echo "<h4>";
for( $i=0; $i < $lengthOfArrayHome; ++$i )
{
$thisNameHome = $person_data_home[$i]["newinfo"];

echo $newinfoContent=$thisNameHome."<br>";
}
echo "</h4>";
?>

<?php
echo "<h2>";
for( $i=0; $i < $lengthOfArrayHome; ++$i )
{
$thisNameHome = $person_data_home[$i]["main"];

echo $mainContent=$thisNameHome."<br>";
}
echo "</h2>";


?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.