querypath

Fix for Fix for QueryPath for removing an XML item

  1. function mymodule_update_languages_xml($form, &$form_state) {
  2.     /*
  3.     ...
  4.     */
  5.     $qp = qp($file);
  6.     if ($form_state['values']['op'] == 'Delete') {
  7.       // Find only items that have id=

Fix for QueryPath for removing an XML item

  1. function mymodule_update_languages_xml($form, &$form_state) {
  2.     /*
  3.     ...
  4.     */
  5.     $qp = qp($file);
  6.     if ($form_state['values']['op'] == 'Delete') {
  7.       $qp->find('languageList')->find(

QueryPath for removing an XML item

  1. function mymodule_add_language_xml($form, &$form_state) {
  2.     /*
  3.     ...
  4.     */
  5.     $qp = qp($file);
  6.     if ($form_state['values']['op'] == 'Delete') {
  7.       $qp->find('languageList')->find('ite

Fix for Now with div.header replacement!

  1. $contents = file_get_contents('./index.html');
  2.  
  3. // Remove DOS carriage returns:
  4. $contents = str_replace(chr(13), '', $contents);
  5.  
  6. // Inital QP
  7. $qp = qp('<div>' . $contents .

Now with div.header replacement!

  1. $contents = file_get_contents('./index.html');
  2.  
  3. // Remove DOS carriage returns:
  4. $contents = str_replace(chr(13), '', $contents);
  5.  
  6. // Inital QP
  7. $qp = qp('<div>' . $contents .

Fix for Remove CR, replace href and src at the same time (with comments)

  1. $contents = file_get_contents('./index.html');
  2.  
  3. // Remove DOS carriage returns:
  4. $contents = str_replace(chr(13), '', $contents);
  5.  
  6. // Inital QP
  7. $qp = qp($contents);
  8.  
  9. // Loop through all element

Remove CR, replace href and src at the same time.

  1. $contents = file_get_contents('./index.html');
  2. $contents = str_replace(chr(13), '', $contents);
  3. $qp = qp($contents);
  4. foreach ($qp->find('[href],[src]') as $link) {
  5.   $src_attr = $link->attr('src')

Fix for expected output xml

  1. <?php
  2. $qp = qp('<?xml version="1.0"? ><quiz><quizinfo/><resultSet/></quiz>', 'quizinfo')
  3.   ->append('<authorName>' . $name . '</authorname>')
  4.   // repeat above for as many elements as you need.
  5.   ->top() // Go back to the top of the document
  6.   ->find('resultSet'); // Search for resultSet section
  7.  
  8. // For each item in the results (wherever you get them), add a result entry
  9. foreach ($results as $result) {
  10.   $qp->branch()
  11.     ->append('<result/>')
  12.     ->find('result:last')
  13.     ->append('<authorName>' . $result->author . '</resultName>')
  14.    // Do that for as many elements as you need
  15. }
  16.  
  17. // Do this to write the output
  18. $qp->writeXML();
  19. ?>

quiz xml

  1. <quiz>
  2. <authorName>admin</authorName>
  3. <authorId>1</authorId>
  4. <title>Sample Quiz</title>
  5. <description>Just a Sample Quiz.</description>
  6. <nodeId>1</nodeId>
  7. <createDate>1244401610</createDate>
  8. <la

expected output xml

  1. <?xml version="1.0"?>
  2. <quiz>
  3.   <quizinfo>
  4.     <authorName>admin</authorName>
  5.     <authorId>1</authorId>
  6.     <title>Sample Quiz</title>
  7.     <nodeId>1</nodeId>
  8.     <createDate>06/21/2009 - 13:41<
Syndicate content