开发者

Using simplexml parsing complex xml

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜