.


:




:

































 

 

 

 


XML- PHP




, , XML - PHP DOM XML, DOM. .

1. domxml_open_mem.

:

object domxml_open_mem (string str)

str, XML -. , DOMDocument.

2. domxml_open_file.

:

object domxml_open_file (string filename)

XML -, filename, DOMDocument. .

, domxml_open_mem() domxml_open_file(), , , DOM.

XML - . . , DomDocument->document_element().

domxml_new_doc(string version), XML -. . , , XML - .

<?

// "persons.xml"

$xmlstr = join('',file('persons.xml'));

// xml-

// .

// ,

// .

if(!$dom = domxml_open_mem($xmlstr)) {

echo " \n";

exit;

}

// ,

//

print_r($dom);

echo "<hr>";

//

// .

//

// <collection>

$root = $dom->document_element();

print_r($root);

echo "<hr>";

?>

14.3. XML- PHP

, XML - - . : , , .

( ) DomNode->node_value() DomNode->get_content() .

DomElement->get_attribute (attr_name). DomNode->child_nodes() .

, , .. , (), , .. . XML_ELEMENT_NODE , , XML_ATTRIBUTE_NODE , , XML_TEXT_NODE , . 1, 2 3 . , , XML -, .

<?

// ,

//

$xmlstr = join('',file('persons.xml'));

if(!$dom = domxml_open_mem($xmlstr)) {

echo " \n";

exit;

}

$root = $dom->document_element();

//

//

// ( <person>)

$nodes = $root->child_nodes();

print_r($nodes);

echo "<hr>";

//

//

foreach($nodes as $node){

//

// <person>,

// ,

//

//

if ($node->tagname=='person'){

// ,

//

//

$currentPers = array();

// id ,

// 'id'

$currentPers['id'] =

$node->get_attribute('id');

//

// <person>.

//

// (<name>,<birth> ..)

$persons_info =

$node->child_nodes();

//

// $node

foreach ($persons_info as $info){

// ,

// (xml-)

if ($info->type==

XML_ELEMENT_NODE) {

// tagname

//

// (),

// get_content()

//

$currentPers[$info->tagname] =

$info->get_content();

}

}

//

//

print_r ($currentPers);

 

echo "<br>";

}

}

?>

14.4. XML

, XML. - XML -. , - , XML -. XML - , , :

...

<person id="20">

<name>

<first></first>

<last></last>

</name>

...

( ) .

...

$str = $currentPers["email"];

if ($currentPers["name"] ==

" ")

echo ", ! ".

" e-mail $str";

...





:


: 2016-10-22; !; : 425 |


:

:

, , .
==> ...

1902 - | 1775 -


© 2015-2024 lektsii.org - -

: 0.016 .