Jump to content

Search the Community

Showing results for tags 'php xml domdocument'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Hi first time poster. I have a PHP/XML blog app and want to give users the ability to delete multiple blog post, with one form submit. The solution is working when blog post ids are not in order. That is if post id selected was 2 and 4, both nodes are deleted from the xml tree. But if the post id selected were 1 and 2, only 2 would be deleted. Has anybody else come across this behavior? Here's some code: psuedo xml <root> <blog id=1><copy>Some copy here</copy></blog> <blog id=2><copy>More copy</copy></blog> <blog id=3><copy>Even more copy</copy></blog> <blog id=4><copy>Last copy</copy></blog> </root> PHP, this is a method in a larger class /** * method usage: $objVar->deletePost($param) * delete client selected xml[blog] entries * @param array, $params : assign $_POST array as argument * @return string, XML */ public function deletePost($params) { foreach ($params as $value){ // assign multi-dim $param[delete][n] to two-dim array $pid=$value; // $value looks like array([0]=>[n],[1]=>[n]) } $xml = new DOMDocument(); // instance of current xml $xml->load($this->fp); // path to file $xml->preserveWhiteSpace = false; //define xpath object, called with query() line 273 $xpath = new DOMXpath($xml); //create temporary DOM xml $tempxml = $xml->documentElement; $pnode = $xml->getElementsByTagName('blog'); foreach($pnode as $key){ //outter loop thru parent nodes foreach($pid as $v){ //inner loop thru pid array if ($key->getAttribute('id')==$v){ //if pid matches blog[id=n] $path = "//root/blog[@id=".$v."]"; $nodelist = $xpath->query($path); $removenode = $nodelist->item(0); //remove the parent/children for matching ids $oldxml = $tempxml->removeChild($removenode); } } } echo $xml->saveXML(); } Thanks in advance, rwhite35
×
×
  • 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.