XML DOM vs Object in Javascript

I recently wrote code that took an XML DOM object and returned the object in Javascript. After talking with a colleague, I wonder if this is worth doing.

Do any of you know any studies or articles that discuss the pros and cons of using any approach?

Example : My code will have an XML DOM object with a structure like this (code changed due to NDA):

<myObject id="123" anotherAttr="hello" customAttr="foo">
  <myChild name="child1" foo="bar"/>
  <myChild name="child2" foo="bar"/>
  <myChild name="child3" foo="bar"/>
</myObject>

and will return this:

{
  id: "123",
  anotherAttr: "hello",
  customAttr: "foo",
  children: [
    {name: "child1", foo: "bar"},
    {name: "child2", foo: "bar"},
    {name: "child3", foo: "bar"}
  ]
}

Three main reasons I would do:

  • The code is more readable. (with the object, I can access the values ​​with dotted notation)
  • I always thought that working with objects was faster than working with the DOM.

: - - , ? ?

+3
2

...

:

1)

var name = xml.selectSingleNode("myObject/myChild")[4].getAttribute("name");
//vs
var name = myObject.children[4].name

2) intellisense ( , IDE, intellisense javascript)

3) , xml ( , )

4) , xml . .

1) . XML, /, .

2) Occam Razor ( , , , ).

3) . , XML. , XML, , JSON . ( , ).

- , JSON, XML javascript, JSON upfront , XML . , , ( ) .

+2

-, JavaScript , Xml HTML. , , "xml data island" (MSXML3), JavaScript-.

, "DOM", ... DOM XML , Mozilla XML Data Island

+2

Source: https://habr.com/ru/post/1792596/


All Articles