php下通过xml_parse解析xml文件

来源:互联网 发布:linux命令vi的使用 编辑:程序博客网 时间:2024/06/10 13:56

xml_parse解析xml文件时候,

很有可能不仅仅调用一次character_handler。

所以在获得xml节点的文本信息的时候,要用连接运算".="。

 

参考 http://jp2.php.net/manual/ro/function.xml-set-character-data-handler.php

 

ken at positive-edge dot com
30-Jan-2002 01:20
the function handler is called several times when it parses the character data.  It doesn't return the entire string as it suggests.  There are special exceptions that will always force the parser to stop scanning and call the character data handler.  This is when:

- The parser runs into an Entity Declaration, such as & (&) or ' (�)
- The parser finishes parsing an entity
- The parser runs into the new-line character (/n)
- The parser runs into a series of tab characters (/t)

And perhaps others.

For instance, if we have this xml content:

<mytag name=�Ken Egervari� title=�Chief Technology Officer�>
    Ken has been Positive Edge&apos;s Chief Technology Officer for 2 years.
</mytag>

The parser will call the character data handler 6 times.  This is what will happen:

1    /n
2    /t
3    Ken has been Positive Edge
4    �
5    s Chief Technology Officer for 2 years.
6    /n

I hope that helps people out.
原创粉丝点击