Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » [PHP-DEV] Is really no one interested? [RSS Feed]

#1 Oct. 31, 2005 09:16:54

Marian K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Is really no one interested?


This is related to feature request 34839.

stochnagara at hotmail dot com

Description:
------------
The class SimpleXMLElement is wonderful and provides a great
functionality.
But I need to extend it and I don't have a way to determine whether a
given SimpleXMLElement is an attribute, an element, a CDATA section and
so on.

So I suggest adding methods getName() and getType(). getName() returns
element's name for elements, attribute's name for attributes and so on.
getType() returns SimpleXMLElement::ELEMENT and so on.




Maybe it is late for 5.1.0 but 5.1.1 is a good place for this to appear.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#2 Oct. 31, 2005 09:20:33

Christian S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Is really no one interested?


On 31.10.2005 10:16 Uhr, Marian Kostadinov wrote:
> This is related to feature request 34839.
>
> stochnagara at hotmail dot com
>
> Description:
> ------------
> The class SimpleXMLElement is wonderful and provides a great
> functionality.
> But I need to extend it and I don't have a way to determine whether a
> given SimpleXMLElement is an attribute, an element, a CDATA section and
> so on.
>
> So I suggest adding methods getName() and getType(). getName() returns
> element's name for elements, attribute's name for attributes and so on.
> getType() returns SimpleXMLElement::ELEMENT and so on.

SimpleXML is meant to be simple and the desicion was made to keep its
API short. Use DOM if you want those more advanced features (there's
dom_import_simplexml() and simplexml_import_dom() for easy and fast
switching between those 2)

chregu

>
>
>
>
> Maybe it is late for 5.1.0 but 5.1.1 is a good place for this to appear.
>

--
christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich
phone +41 1 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71http://www.bitflux.ch| | GPG 0x5CE1DECB

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#3 Oct. 31, 2005 09:27:58

Marian K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Is really no one interested?


> SimpleXML is meant to be simple and the desicion was made to keep its
> API short. Use DOM if you want those more advanced features (there's
> dom_import_simplexml() and simplexml_import_dom() for easy and fast
> switching between those 2)
>
> chregu

SimpleXML is simple and that is great. But such a CORE functionality
like getting a SimpleXML node own name and type is not available.
It's funny that one can access absolutely everything about a node
children, attributes and so on very easily and intuitively, but cannot
access node's own name:)

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#4 Nov. 1, 2005 07:21:48

Petar N.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Is really no one interested?


On Monday 31 October 2005 11:27, Marian Kostadinov wrote:
> > SimpleXML is meant to be simple and the desicion was made to keep its
> > API short. Use DOM if you want those more advanced features (there's
> > dom_import_simplexml() and simplexml_import_dom() for easy and fast
> > switching between those 2)
> >
> > chregu
>
> SimpleXML is simple and that is great. But such a CORE functionality
> like getting a SimpleXML node own name and type is not available.
> It's funny that one can access absolutely everything about a node
> children, attributes and so on very easily and intuitively, but cannot
> access node's own name:)

I don't think it's a core feature since the tree hierarchy of the XML is well
defined and you have a well-formed DTD. As Christian spotted - the DOM
functionallities could serve you well. The basic and simple API attracts so
much users, let's keep it this way.

--

Cyberly yours,
Petar Nedyalkov
Devoted Orbitel Fan :-)

PGP ID: 7AE45436
PGP Public Key:http://bu.orbitel.bg/pgp/bu.ascPGP Fingerprint: 7923 8D52 B145 02E8 6F63 8BDA 2D3F 7C0B 7AE4 5436pgp8PTSsLAjfB.pgpDescription:PGP signature

Attachments:
attachment pgp8PTSsLAjfB.pgp (189 bytes)

Offline

#5 Nov. 1, 2005 07:48:45

Marian K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Is really no one interested?


Who says that I have a well-formed DTD? DTD is not necessary in many
cases. I will illustrate with example why DOM is too "complex" ...
compared to SimpleXML.

<?php
//These are my 2 XML documents. No DTD - just a simple xml structure.
$xml1 = '<root1><q/><a><b><c><d>hi1</d></c></b></a><q/></root1>';
$xml2 = '<root2><q/><a><b><c><d>hi2</d></c></b></a><q/></root2>';

$sxe1 = new SimpleXMLElement ($xml1);
$sxe2 = new SimpleXMLElement ($xml2);

//Easy access to a node. It's great!
echo $sxe1->a->b->c->d;
echo $sxe2->a->b->c->d;

//But how can I understand what is the name of the root node?
$dom_sxe = dom_import_simplexml($sxe1);

//Hooray, we've got node name
echo $dom_sxe->nodeName;

//And what happens if element sequence changes? .
echo
$dom_sxe->childNodes->item(1)->firstChild->firstChild->firstChild->nodeValue;
//... hm... I prefer SimpleXML.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#6 Nov. 1, 2005 07:51:52

Christian S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Is really no one interested?


On 1.11.2005 8:48 Uhr, Marian Kostadinov wrote:
> Who says that I have a well-formed DTD? DTD is not necessary in many
> cases. I will illustrate with example why DOM is too "complex" ...
> compared to SimpleXML.
>
> <?php
> //These are my 2 XML documents. No DTD - just a simple xml structure.
> $xml1 = '<root1><q/><a><b><c><d>hi1</d></c></b></a><q/></root1>';
> $xml2 = '<root2><q/><a><b><c><d>hi2</d></c></b></a><q/></root2>';
>
> $sxe1 = new SimpleXMLElement ($xml1);
> $sxe2 = new SimpleXMLElement ($xml2);
>
> //Easy access to a node. It's great!
> echo $sxe1->a->b->c->d;
> echo $sxe2->a->b->c->d;
>
> //But how can I understand what is the name of the root node?
> $dom_sxe = dom_import_simplexml($sxe1);
>
> //Hooray, we've got node name
> echo $dom_sxe->nodeName;
>
> //And what happens if element sequence changes? .
> echo
> $dom_sxe->childNodes->item(1)->firstChild->firstChild->firstChild->nodeValue;
> //... hm... I prefer SimpleXML.

use xpath :) as easy as simplexml and much more powerfull, IMHO

and noone said you should use exclusively dom.

chregu


--
christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich
phone +41 1 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71http://www.bitflux.ch| | GPG 0x5CE1DECB

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#7 Nov. 1, 2005 08:05:55

Petar N.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Is really no one interested?


On Tuesday 01 November 2005 09:48, Marian Kostadinov wrote:
> Who says that I have a well-formed DTD? DTD is not necessary in many
> cases. I will illustrate with example why DOM is too "complex" ...
> compared to SimpleXML.

Well, If you are free to change the XML structure at any time - where's the
point in wondering if an element is a parameter, a CDATA or an element? You
can change everything to element and CDATA and that's all. If you have a
fixed XML structure, that's not supposed to change, having a DTD is
obligatory in orther to maintain consistency of the format.
So, you can either work without using getType (since you define the XML
structure yourself), or use a more complex API that will serve you well.

>
> <?php
> //These are my 2 XML documents. No DTD - just a simple xml structure.
> $xml1 = '<root1><q/><a><b><c><d>hi1</d></c></b></a><q/></root1>';
> $xml2 = '<root2><q/><a><b><c><d>hi2</d></c></b></a><q/></root2>';
>
> $sxe1 = new SimpleXMLElement ($xml1);
> $sxe2 = new SimpleXMLElement ($xml2);
>
> //Easy access to a node. It's great!
> echo $sxe1->a->b->c->d;
> echo $sxe2->a->b->c->d;
>
> //But how can I understand what is the name of the root node?
> $dom_sxe = dom_import_simplexml($sxe1);
>
> //Hooray, we've got node name
> echo $dom_sxe->nodeName;
>
> //And what happens if element sequence changes? .
> echo
> $dom_sxe->childNodes->item(1)->firstChild->firstChild->firstChild->nodeValu
>e; //... hm... I prefer SimpleXML.

--

Cyberly yours,
Petar Nedyalkov
Devoted Orbitel Fan :-)

PGP ID: 7AE45436
PGP Public Key:http://bu.orbitel.bg/pgp/bu.ascPGP Fingerprint: 7923 8D52 B145 02E8 6F63 8BDA 2D3F 7C0B 7AE4 5436pgpPy3wFRmlFk.pgpDescription:PGP signature

Attachments:
attachment pgpPy3wFRmlFk.pgp (189 bytes)

Offline

#8 Nov. 1, 2005 11:28:53

Rob R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Is really no one interested?


Marian Kostadinov wrote://But how can I understand what is the name of the root node?
$dom_sxe = dom_import_simplexml($sxe1);

//Hooray, we've got node name
echo $dom_sxe->nodeName;

//And what happens if element sequence changes? .
echo
$dom_sxe->childNodes->item(1)->firstChild->firstChild->firstChild->nodeValue;
//... hm... I prefer SimpleXML.The API is to be kept simple and what you are asking for can be doneextending the SimpleXMLElement and the functions are a whole 1 line ofuser code:<?php
class cNode extends SimpleXMLElement {
function getName() {
return dom_import_simplexml($this)->nodeName;
}

function getType() {
return dom_import_simplexml($this)->nodeType;
}
}

$xml = '<root />';

$sxe = simplexml_load_string($xml, 'cNode');
print $sxe->getName()."\n";
print $sxe->getType()."\n";
?>

Of course XPath could be used in place of DOM too though.

Rob

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

  • Root
  • » PHP
  • » [PHP-DEV] Is really no one interested? [RSS Feed]

Board footer

Moderator control

Enjoy the 18th of November
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support