开发者

Using simplexml parsing complex xml

开发者 https://www.devze.com 2023-03-06 12:57 出处:网络
I am using simplexml to extract information from large xml files and store the results in a mysql database. It\'s all working fine but how do I get at the days in this xml where the days are not attri

I am using simplexml to extract information from large xml files and store the results in a mysql database. It's all working fine but how do I get at the days in this xml where the days are not attributes or inside tags

<operatingInformation>
    <normalOperation>
        <operatingDays>
            <days&g开发者_StackOverflowt;
               <monday />
               <tuesday />
            </days>
        </operatingDays>
    </normalOperation>
</operatingInformation>

What I need is to extract the names of the days so I can add them to my database table.


With your XML document parsed as $xml, this will loop over the days and print their names:

foreach ( $xml->normalOperation->operatingDays->days->children() as $dayElem ) {
    print $dayElem->getName() ."\n";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消