Git Product home page Git Product logo

simplexml_debug's People

Contributors

imsop avatar joshtronic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

simplexml_debug's Issues

simplexml_tree should use namespace URIs not prefixes (by default)

The ability to reference namespaces by their local prefix in SimpleXML is certainly very handy, but I'm increasingly convinced that it shouldn't be relied on. It is perfectly possible for the same file to later be generated using different prefixes for the same namespaces (or even swapping them if they are e.g. "ns1" and "ns2"!).

As this instructional blog post puts it "You’ll have to decide for yourself whether it’s a risk worth taking or not."

simplexml_tree currently outputs access examples using this feature, which could encourage bad practice.

Should an option be provided to choose which style to output? Perhaps change the second parameter ($include_string_content) to be a hash or bit mask controlling various formatting options?

Handle arrays returned by ->xpath()

The xpath() method doesn't return a SimpleXMLElement, but an actual array of objects. simplexml_dump() will currently return an error if you try to pass it this array.

Keeping this limitation keeps the function simple as it always gets a single SimpleXMLElement object, and doesn't need to do any recursion or similar. However, it means that not every SimpleXML operation can be trivially debugged with this function.

Would need to consider how to handle completely unrelated data types, including arrays with some SimpleXMLElement values as well as some others:

  • Fatal error on unhandled type?
  • Warn and continue (e.g. in an array loop)?
  • Fall back to another debug function, such as print_r or var_export?
  • Should arrays be handled recursively, or as a single loop, with nested arrays treated as "unhandled"?

Better License?

The intention of using CC-BY was that it's simple but official.

Some have pointed out, though, that it's not generally a good fit for code, and mixing with other licences.

Attributes in default namespace behave oddly

There seems to be a bug (or misfeature?) in SimpleXML where attributes in the default namespace don't show if you call ->attributes($default_namespace_uri) rather than ->attributes('', true).

Because of simplexml_dump's attempts to display namespace information, this leads to data disappearing from view with innocuous XML like this:

<?php
include 'simplexml_dump.php';

$xml = <<<XML
<?xml version="1.0"?>
<Foo xmlns="http://example.com">
        <Bob InvisibleAttribute="You ain't seen me, right?">
                <MaskingChildElement />
        </Bob>
</Foo>
XML;

$sx_Foo = simplexml_load_string($xml);
simplexml_dump($sx_Foo->Bob);

Element in default namespace displayed wrong if attribute has a namespace

While constructing tests for #3, I found a different oddity: currently, I'm relying on ->getNamespaces(false) returning the namespace of the current element, but that's not actually what it does. Instead, it lists all namespaces used by the current element, including its attributes.

Consider the following:

<?xml version="1.0" standalone="yes"?>
<notinnamespace xmlns:test="http://example.com" test:isinnamespace="true" />

Here, the prefix test is used in the element (by the attribute) but isn't the namespace to which the element belongs. Since there is no default namespace defined, there's no '' key in the getNamespaces output, so the output is [ 'test' => 'http://example.com' ], leading to broken dump output.

simplexml_tree doesn't show ->children(...) if root element is prefixed

If the root element of a document is not in the default namespace, but is instead a prefixed node, it is necessary to immediately call ->children() to "select" that namespace. simplexml_tree doesn't currently show this call, unlike other namespace switches.

This is extremely common with SOAP documents, where the root element is the SOAP Envelope, which is not generally set as the default namespace.

See e.g. http://codepad.viper-7.com/eVrQ1u where the root element is "soapEnv:Envelope"

Can't distinguish single nodes from lists with one item

There is currently no way of distinguishing between a single element (e.g. $sxml->Result[0]) and a list of elements (e.g. $sxml->Result or $sxml->children()) which happens to include only one item. They can however behave differently - foreach ( $sxml->Result[0] as $result ) is equivalent to foreach ( $sxml->Result[0]->children() as $result ).

As far as I can see, there is no way of determining this with the current API. However, since the behaviour is different, the extension itself clearly tracks this distinction. It should probably be raised with the maintainers to add PHP access to this property for a future release.

output formatting

very nice
It would be nice if its output was more matched to var_dump
datatype(length) value for example

string(5) "item1"
as opposed to
(string) 'item1' (5 chars)

// var_dump output
object(SimpleXMLElement)#4 (1) {
  ["item"]=>
  string(5) "item1"
}

also if you pass a custom class to it, it is not reflected in output

// simplexml_load_string($xml, 'SimpleXMLExtended')
// var_dump output
object(SimpleXMLExtended)#4 (1) {
  ["item"]=>
  string(5) "item1"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.