How to output all the content of nodes with the same name in XML?

Source: Internet
Author: User
When the existing PHP code outputs an XML node, it can only output the content of the first node with the same name & quot; 100 & quot;. How can I output the content of all nodes? Existing Code: & amp; lt ;? Php * $ xmlstring original content: & amp; lt ;? XML version & quot; 1.0 & quot ;? & Amp; gt; & amp; lt ;! DOCTYPEGetUserInfo & amp; gt;-& amp; lt; Get... when the existing PHP code outputs an XML node, only the content of the first node with the same name "100" can be output ". how can I output the content of all nodes?

Existing Code:
/* $ Xmlstring original content:


-
Id * cn
100
101
102
103
105

*/

$ Xmldoc = new DOMDocument ();
$ Xmldoc-> loadXML ($ xmlstring );
$ Users = $ xmldoc-> getElementsByTagName ('getuserinfo ');
Foreach ($ users as $ user ){

$html .= 'outputCustomer:'.get_txt($user,'Customer').'
';$html .= 'outputGeo:'.get_txt($user,'GeocallCLI').'
';

}
Echo $ html;

Function get_txt ($ parent, $ name ){

$nodes = $parent->getElementsByTagName($name);return $nodes->item(0)->nodeValue;

}
?>

How to output only Id Cn NodeId, not id * cn

Reply content:

When the existing PHP code outputs an XML node, it can only output the content of the first node with the same name "100". How can I output the content of all nodes?

Existing Code:
/* $ Xmlstring original content:


-
Id * cn
100
101
102
103
105

*/

$ Xmldoc = new DOMDocument ();
$ Xmldoc-> loadXML ($ xmlstring );
$ Users = $ xmldoc-> getElementsByTagName ('getuserinfo ');
Foreach ($ users as $ user ){

$html .= 'outputCustomer:'.get_txt($user,'Customer').'
';$html .= 'outputGeo:'.get_txt($user,'GeocallCLI').'
';

}
Echo $ html;

Function get_txt ($ parent, $ name ){

$nodes = $parent->getElementsByTagName($name);return $nodes->item(0)->nodeValue;

}
?>

How to output only Id Cn NodeId, not id * cn

Which of the following experts can answer this question?
My top

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.