Giter Site home page Giter Site logo

Comments (4)

nielsdos avatar nielsdos commented on May 29, 2024 1

The new behaviour is the right behaviour, and also how browsers behave.

When you create an element in a namespace, it doesn't add an xmlns attribute into the document tree. Therefore, getAttribute('xmlns') returns NULL. The serializer invoked via saveXML() adds an xmlns attribute in its string output such that the namespace is preserved when parsing the output. However, the attribute is still not added in the document tree.

When you now reload the document by parsing the output from saveXML(), the attribute will be added to the document tree because the input string had the attribute.

You can check this is the same what your browser does:

doc = document.implementation.createDocument('', '');
doc.appendChild(doc.createElementNS('http://www.w3.org/2000/svg', 'svg'));
console.log(doc.firstChild.getAttribute('xmlns')) // returns null
console.log( (new XMLSerializer).serializeToString(doc) ) // now it adds the xmlns attribute in the output, but it still doesn't exist in the document

The "old DOM" behaviour is wrong: it mixes the concept of an internally defined namespaces with attributes that are observable.

I’d have expected that serializing and parsing produces an identical state of the document, but it didn’t.

There are multiple cases where the use of namespaces can lead to invalid XML, and so there are rules that are laid out by the spec on how to make the serializer resolve these issues.

from php-src.

nielsdos avatar nielsdos commented on May 29, 2024 1

BTW If your intention is to get the default namespace in a certain context node, you can use lookupNamespaceURI.

from php-src.

nielsdos avatar nielsdos commented on May 29, 2024 1

Makes sense. Next time I will cross check with the browser behavior in advance. ☺️

FTR: I don't mind answering questions if anything is unclear or seems off though. :-)

from php-src.

ausi avatar ausi commented on May 29, 2024

Thank you for the detailed explanation!

You can check this is the same what your browser does

Makes sense. Next time I will cross check with the browser behavior in advance. ☺️

from php-src.

Related Issues (20)

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.