<?php
$data ='<?xml version="1.0" encoding="utf-8"?>
<infos>
<info time="1247640983" count="0" detail="will be updated" uid="1" path="/var/www/user/1/codjng.avi">MOT</info>
<info time="1247640983" count="0" detail="will be updated" uid="2" path="/var/www/user/2/codjng.zip">HAI</info>
<info time="1247640983" count="0" detail="will be updated" uid="3" path="/var/www/user/3/codjng-3.txt" />
</infos>';
$xml = simplexml_load_string($data);
// select
$elements = $xml->xpath("/infos/info");
foreach ($elements as $ele) {
echo $ele[0];
}
echo "<pre>" . htmlspecialchars($xml->asXML()) . "</pre><hr/>";
// delete first element
unset($elements[0][0]);
echo "<pre>" . htmlspecialchars($xml->asXML()) . "</pre><hr/>";
// update second element
$elements[1]["path"] = "/var/www/user/2/codjng-modify.zip";
echo "<pre>" . htmlspecialchars($xml->asXML()) . "</pre>";
// insert element
$ele = $xml->addChild("info");
$ele->addAttribute("count", "1000");
$ele[0] = "bla bla codjng";
echo "<pre>" . htmlspecialchars($xml->asXML()) . "</pre>";
?>
skip to main |
skip to sidebar
Note anything I want
Friday, July 17, 2009
simplexml xpath php, select insert update delete
Tags
.BAT
.htaccess
.NET
500
[Visual] C [++]
absolute
admin
ADODB
advertise
ajax
apache
API
arguments
array
ASP
attrib
auto-post
AutoIT
awk
back
Back-end
background
backup
BAT
blogger
bookmark
branch
breadcrumb
buffer
bug
C#
cache
Caesar
CafeF
canvas
CAS
case-when
centos
cgi
CIDR
ckEditor
clean-up
cmd
cms
color
column
command
commit
compile
component
config
connection
cookie
cool
copy db
crawler
credential
CSS
cURL
daemon
datafile
delete
design
df
Diem
disk-space
distinct
DLL
doctrine
documentation
domain
DomDocument
download
editor
encode
encrypt
English
enter
error
excel
exception
extension
facebook
fdisk
filter
find-exec
firefox
fix
fixture
flick
foreign-key
form
function
gdata
git
Google
groupBy
gzip
haproxy
HashSet
having
helper
history
hook
hosting
HTML
HTML5
httpd
I18N
ifconfig
image
imagick
innerHTML
input
install
ip
Iphone
j2me
Java
Javascript
join
Joomla
jQuery
JSP
keyboard
LAN
learning
LIGHTTPD
Linux
lock
log
log4j
lynx
margin
menu
merge
Midlet
mobile
model
mount
msisdn
MySQL
NetBeans
network
nfs
nodejs
not4you
npm
oauth
Opacity
option
Oracle
order
outlook
pagination
paging
pdf
pear
performance
perl
permission
persist
PHP
php-block
php.ini
ping
plugin
popup
position
procedure
process
progress-bar
Properties
proxy
PSD
PTS
query
radio
radis
random
raw-request
recursive
redis
regex
relocate
Repository
require_once
revert
rms
rotate
route
RSA
rss
rsync
runable
schema.yml
scp
search
select
serial
server
Service Pack 3
session
setFlash
setInterval
sfConfig
sfDoctrineGuard
shell
shop-cart
sign
smarty
smiliebox
SMS
soap
SoapClient
socks
solved
split
sql
ssh
SSO
stderr
stdin
stdout
step-by-step
storage
submit
svn
svnadmin
switch
symbian
symfony
sync
table
tablespace
template
thread
thumbnail
timeout
Tree Menu
trigger
trunk
unicode
update
upload
utf8
UUID
validator
vba
VBS
vbulletin
VC Corp
version
virtual-host
VirtueMart
Visual Basic
VPN
WAP
warning
web-server
webservice
widget
Windows XP
winscp
Word
wordpress
wsdl
xdebug
xml
yahoo
yaml
youtube
yum
Blog Archive
-
▼
2009
(207)
-
▼
July
(42)
- Rounded Corners Without Images
- Install Berkeley DB support PHP (db4) and Java API...
- Read first line in file by java
- Write new file in Java
- Use javac to compile package
- text input for copying
- How to compile a package by javac
- How to use Java API to work with Berkley DB
- java-6-openjdk or java-6-sun in Ubuntu
- Unix File Permissions
- Set CLASSPATH for running Java class in Ubuntu
- PHP Script to Convert Windows-1252 string to UTF-...
- Script to Convert Windows-1252 files to UTF-8
- Rounded corners in CSS
- CSS Navigation Menu
- CSS clear property
- Tutorial: get start with lucene in ubuntu
- cache url file
- div with scrollbar
- simplexml xpath php, select insert update delete
- download file server
- refresh .bashrc after add alias to take effect
- convert .htaccess apache to lighttpd config - rewr...
- apt-get install remove update
- phpize - command not found
- iframe access function of window parent
- run php script without extension
- copy remote file
- ob_flush flush output_buffering php.ini
- OpenID Yahoo - Google - MSN - and more
- recursive move dir
- Download multiple files simultaneously with curl a...
- get all subdirs in some root dirs
- http://www.ericmmartin.com/simplemodal/
- setInterval setTimeout with function containt argu...
- Normalizes the slashes in an path
- check cookie is disabled
- session_start();
- Preventing Multiple Submits
- You have to wait to see download link
- Available DBA handlers
- Ajax Upload
-
▼
July
(42)
Link List
- How to get full filename of the snapshot taken in JSR 234
- Using DmMedia
- Managing Hierarchical Data in MySQL
- JQuery Tabs
- Custom listBy* methods in widget list in Diem
- Diem Widget
- Oracle
- JAVA - Build WebSerivce
- SOAP - Using classmap (PHP)
- VB6 - Hook keyboard and Mouse
- WordPress - Create new widget
- Symfony - Create new plugin
Copyright 2010 Love Codjng . Powered by Blogger
Blogger Templates created by Deluxe Templates Wordpress by thebookish
1 comment:
$obj = simplexml_load_file('C:\Program Files\Yahoo!\Messenger\Media\Smileys\emoticons.xml');
$result = $obj->xpath('/emoticons/emoticon');
while(list( , $node) = each($result)) {
$arr = $node->xpath('shortcuts/shortcut');
$a = $node->attributes();
echo '"' . addcslashes($arr[0],'"\\') . '": "' . $a['fname'] . ".gif\"\n";
}
Post a Comment