zoukankan      html  css  js  c++  java
  • 2017.5.17

    xml-file 1

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <note>
    <firstname>My name is WHAT</firstname>
    <lastname>My name is WHO</lastname>
    <body>My name is CHIKA CHIKA Slim-Shady</body>
    </note>

    xml-file 2

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <note>
    <firstname>My name is WHAT</firstname>
    <lastname>My name is WHO</lastname>
    <body><b>My name is CHIKA CHIKA Slim-Shady</b></body>
    </note>

    question:how can i get body content in file 2

    $note = simplexml_load_file("xml-file 1");
    echo $note->body;  //My name is CHIKA CHIKA Slim-Shady

    $note = simplexml_load_file("xml-file 2");
    echo $note->body;  //empty

     solution 1:asXML() method will give you the "outerXML" which you then remove with strip_tags

    echo strip_tags($note->body->asXml());  //My name is CHIKA CHIKA Slim-Shady

    solution 2:importing the node into DOM and then getting it's nodeValue

    echo dom_import_simplexml($note->body)->nodeValue;
  • 相关阅读:
    [CTSC2008]网络管理
    [HNOI/AHOI2018]转盘
    [HAOI2015]树上染色
    [CTSC2017]吉夫特
    [CTSC2011]幸福路径
    Comet OJ
    2019各省省选试题选做
    HNOI2019 简要题解
    HNOI2019游记
    JOISC2019 简要题解
  • 原文地址:https://www.cnblogs.com/zhanghonggang/p/6867183.html
Copyright © 2011-2022 走看看