Re: How to add new functions to SimpleXML extention
| From: | Sterling Hughes | Date: | Mon, 12 Jan 2004 19:23:40 +0000 |
| Subject: | Re: How to add new functions to SimpleXML extention | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-6998@lists.php.net to get a copy of this message | ||
Funny, i writing a response to adam's message while this got to the
mailing list. Take a look at my response to adam, as it covers this
patch as well.
-Sterling
> Hi!
>
> I'm just playing with simplexml and wonder if two new functions of the
> simplexml_element object would be usefull: getName() and getParent(). I'm
> interesting in adding them to the extention, if possible. What should I do
> for this? (I also think that it may be in FAQ, but I did not find that info
> with my search skills).
> Basically, this is my first experiment with PHP Extensions. I may be wrong
> with my code, but tests pass is ok
>
> -----------------------
> Thank you for time,
> Alexander Netkachev
> http://devlink.narod.ru/
>
> Code for getName function:
> /* {{{ getName()
> */
> SXE_METHOD(getName)
> {
> char *name;
> xmlNodePtr node; // current node
> php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
> GET_NODE(sxe, node);
> if (node && (name = (char *)(node->name))) {
> RETURN_STRING(name, 1);
> }
> RETURN_EMPTY_STRING();
> }
> /* }}} */
>
> /* {{{ getParent()
> */
> SXE_METHOD(getParent)
> {
> xmlNodePtr node; // current node
> xmlNodePtr pNode; // node->parent
> php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
> GET_NODE(sxe, node);
> if (node && (pNode = node->parent)) {
> _node_as_zval(sxe, pNode, return_value TSRMLS_CC);
> return;
> }
> RETURN_NULL();
> }
> /* }}} */
>
> File: ext/simplexml/tests/019.phpt
> --TEST--
> SimpleXML: Test getParent() and getName() functions
> --SKIPIF--
> <?php if (!extension_loaded("simplexml")) print "skip"; ?>
> --FILE--
> <?php
> $doc = simplexml_load_string('<html><body></body></html>');
> var_dump(trim($doc->body->getParent()->getName()));
> echo '--done--';
> ?>
> --EXPECT--
> string(4) "html"
> --done--
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>