background image

function

 __construct(

$xmlFile

 ='', 

$version

 ='1.0', 

$encoding

 = 'UTF-8'){ 

$this

->version = 

$version

$this

->encoding = 

$encoding

$this

->xml = 

new

 DOMDocument(

$version

$encoding

); 

if

(

$xmlFile

)

$this

->xml->load(

$xmlFile

); 

function

 getRootEle(

$rootTag

){ 

$this

->xmlRoot = 

$this

->xml->getElementsByTagName(

$rootTag

)->item(0); 

function

 getSeachItem(

$itemsTag

$seachNode

$seachValue

){ 

$this

->items = 

$this

->xml->getElementsByTagName(

$itemsTag

); 

$this

->items->length; 

for

(

$i

=0; 

$i

<

$this

->items->length; 

$i

++){ 

$item

 = 

$this

->items->item(

$i

);

//

 

元素

$node

 = 

$item

->getElementsByTagName(

$seachNode

);

//

 

节点

for

(

$j

 = 0; 

$j

$node

->length; 

$j

++){ 

$subNode

 = 

$node

->item(

$j

); 

if

(

$seachValue

 == 

$subNode

->nodeValue){ 

$this

->seachNode = 

$subNode

$this

->seachItem = 

$item

$this

->seachValue = 

$subNode

->nodeValue; 

break

(2); 



return

 (

$this

->seachNode) ? true : false; 

function

 update(

$nodeValue

$nodeTag

 = '',

$append

 = false, 

$index

 = 0){ 

if

(

$append

){ 

if

(

$nodeTag

$this

->seachItem->getElementsByTagName(

$nodeTag

)->item(

$index

)->nodeValue += 

$nodeValue

else

 

$this

->seachNode->nodeValue += 

$nodeValue

}

else

if

(

$nodeTag

$this

->seachItem->getElementsByTagName(

$nodeTag

)->item(

$index

)->nodeValue = 

$nodeValue

else

 

$this

->seachNode->nodeValue = 

$nodeValue