# Is really no one interested?

- Thread: https://externals.io/message/19856
- Original archive: https://news-web.php.net/php.internals/19856
- Started by Marian Kostadinov on 2005-10-31T09:16:21+00:00
- Messages: 8
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #19856 — Marian Kostadinov — 2005-10-31T09:16:21+00:00

URL: https://externals.io/message/19856#19856

This is related to feature request 34839.

[12 Oct 7:58pm CEST] 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.

---

## #19857 — Christian Stocker — 2005-10-31T09:19:38+00:00

URL: https://externals.io/message/19856#19857 · In reply to: #19856

> This is related to feature request 34839.
> 
> [12 Oct 7:58pm CEST] 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 71
http://www.bitflux.ch | christian.stocker@bitflux.ch |  GPG 0x5CE1DECB

---

## #19858 — Marian Kostadinov — 2005-10-31T09:27:27+00:00

URL: https://externals.io/message/19856#19858 · In reply to: #19857

> 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:)

---

## #19868 — Petar Nedyalkov — 2005-11-01T07:21:01+00:00

URL: https://externals.io/message/19856#19868 · In reply to: #19858

> > […]
>
> 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.asc
PGP Fingerprint: 7923 8D52 B145 02E8 6F63 8BDA 2D3F 7C0B 7AE4 5436

---

## #19871 — Marian Kostadinov — 2005-11-01T07:48:13+00:00

URL: https://externals.io/message/19856#19871 · In reply to: #19868

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.

---

## #19872 — Christian Stocker — 2005-11-01T07:51:07+00:00

URL: https://externals.io/message/19856#19872 · In reply to: #19871

> 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 71
http://www.bitflux.ch | christian.stocker@bitflux.ch |  GPG 0x5CE1DECB

---

## #19873 — Petar Nedyalkov — 2005-11-01T08:04:33+00:00

URL: https://externals.io/message/19856#19873 · In reply to: #19871

> 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.asc
PGP Fingerprint: 7923 8D52 B145 02E8 6F63 8BDA 2D3F 7C0B 7AE4 5436

---

## #19881 — Rob Richards — 2005-11-01T11:35:14+00:00

URL: https://externals.io/message/19856#19881 · In reply to: #19871

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 done 
extending the SimpleXMLElement and the functions are a whole 1 line of 
user 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
