1

XMLファイルを継続的に書き換えずにXMLファイルにデータを追加するコードを作成するために何ができるかを理解しようとしています。

すべてのフォームエントリを保存できる必要があります。現在、フォームが送信されるたびに保存できます。新しいXMLファイルを作成し、古いXMLファイルを消去します。

これは本当に簡単に修正できるかもしれませんし、私は本当にばかげていますが、DOM構文を調べたのですが、結果を変更するために何を変更できるかわかりません。

// define configuration file name and path
$configFile = 'abook.xml';

// if form not yet submitted
// display form
if (!isset($_POST['submit'])) {

  // set up array with default parameters
  $data = array();
  $data['name'] = null;
  $data['email'] = null;
  $data['caddress'] = null;
  $data['city'] = null;
  $data['state'] = null;
  $data['zipcode'] = null;
  $data['phone'] = null;
  $data['pug'] = null;
  $data['comment'] = null;
  $data['subscribe'] = null;

  // read current configuration values
  // use them to pre-fill the form
  if (file_exists($configFile)) {
    $doc = new DOMDocument();
    $doc->preserveWhiteSpace = false;
    $doc->load($configFile);
    $address = $doc->getElementsByTagName('address');
    foreach ($address->item(0)->childNodes as $node) {
      $data[$node->nodeName] = $node->nodeValue; 

    }        
  }

その間にPHPフォームと検証コードがあり、最後にXMLタグを再度使用します。

  // generate new XML document
  $doc = new DOMDocument();

  // create and attach root element <configuration> 
  $root = $doc->createElement('addressbook');
  $configuration = $doc->appendChild($root);

  // create and attach <oven> element under <configuration>
  $address = $doc->createElement('address');
  $configuration->appendChild($address);

  // write each configuration value to the file
  foreach ($config as $key => $value) {
    if (trim($value) != '') {
      $elem = $doc->createElement($key);
      $text = $doc->createTextNode($value);
      $address->appendChild($elem);
      $elem->appendChild($text);          
    }
  }

  // format XML output



  // save XML file
  $doc->formatOutput = true;
  $doc->save($configFile) or die('ERROR: Cannot write configuration file');      
  echo 'Thank you for filling out an application.';
}  

私はこれで本当に新しいので、私のコードがかなり乱雑であるならば申し訳ありません。

XMLファイルにリンクしたXSLファイルを扱っている2番目の部分ですが、変換に使用した構文に関係なく、テーブルに保存するために何も機能しません。

繰り返しになりますが、これがXMLを作成するためにPHPを設定した方法が原因である可能性があるかどうかはわかりません。

4

0 に答える 0