XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] Why does XML call them "attributes" and not name-valuepairs?

Hi,

that depends on the implementation

Here is an especially compact one that only uses 8 bytes for an element or attribute node on average: https://blog.grijjy.com/2020/10/07/an-xml-dom-with-just-8-bytes-per-node/

With a custom memory allocator and relative addressing, you only need 9 _bit_ for a pointer.



Cheers,
Benito 
On 16.01.22 20:04, Dimitre Novatchev wrote:
> The attribute takes up exactly the same amount of memory as the
> element.

Not true!

I ran a small C# program that shows the sizes of a bare (just created) XmlDocument, XmlElement and XmlAttribute.

Here are the results:

an XmlDocument: 3176 bytes

an XmlElement: 656 bytes

an XmlAttribute: 152 bytes.

Thus an XmlElement takes more than 4 times the memory that an XmlAttribute takes.

So, when memory is important (and it almost always is!), converting elements to attributes can significantly reduce the memory footprint of an XML processing application.

P.S.
These results may vary for different XML DOM implementations, but I expect them to be similar -- maybe other people could share their results?

Here is the code I used:

using System;
using System.Xml;

class Program
{
    static void Main(string[] args)
    {
        var mem1 = GC.GetTotalMemory(true);
        var doc = new XmlDocument();
        var mem2 = GC.GetTotalMemory(true);
        var elem = doc.CreateElement("x");
        var mem3 = GC.GetTotalMemory(true);
        var attr = doc.CreateAttribute("y");
        var mem4 = GC.GetTotalMemory(true);
        Console.WriteLine($"XmlDocument: {mem2 - mem1} bytes");
        Console.WriteLine($"XmlElement: {mem3 - mem2} bytes");
        Console.WriteLine($"XmlAttribute: {mem4 - mem3} bytes");
    }
}

And here is the result:

XmlDocument: 3176 bytes
XmlElement: 656 bytes
XmlAttribute: 152 bytes


Cheers,
Dimitre




On Sun, Jan 16, 2022 at 10:20 AM Kit <kit.saels@gmail.com> wrote:
The attribute takes up exactly the same amount of memory as the
element. So memory is not an argument. I like to use attributes when
it is readable - for example when exporting a database table.
--
Kit


ne 16. 1. 2022 v 19:10 odesílatel Dimitre Novatchev
<dnovatchev@gmail.com> napsal:
>
> > Computer memory space is not important today.
>
> Completely disagree.
>
> Availability of computer memory is and will always be important, and this is being proven by everyday needs and applications !
>
> With larger available RAM we get new applications that use/require enormous (in yesterday's terms) amount of memory that tests even today's limits. This is what drives making new generations of computers with more and more RAM.
>
> So, on the contrary: today it has become important not to be stopped by the "available memory" barriers.
>
> This is why we use streaming almost everywhere, and XSLT 3.0 for example (not to mention obvious other streaming - needing applications like video (Netflix!!!)) gives us a standard W3C-endorsed normative solution for working with huge (whatever this means at a certain point of time) XML documents.
>
> > The place on the screen is more important if one reads or edits such structured text
>
> If one reads a one-page document, then yes.
>
> But even 22 years ago there were XML documents "big" enough (like Hamlet.xml -- about 200KB) to overflow not one but many computer screens.
>
> This was one of the main driving reasons while we needed something more than reading and intuition in order to be able to navigate through an XML document and ask questions about it and get answers to these questions. This is what gave us XPath, XQuery and XSLT.
>
> And every developer knows about SoC (Separation of concerns), SRP (Single Responsibility Principle), Interface Segregation Principle (Many client-specific interfaces are better than one general purpose interface: no code should be forced to depend on methods it does not use), DRY (Don't repeat yourself).
>
> If we know in advance that some object doesn't have certain properties and abilities, like children, descendants, etc., specifying such properties and abilities for this object contradicts all these principles and is what we call an "antipattern" (a nice synonym for "stupid" and "bloated").
>
> Thanks,
> Dimitre
>
> On Sun, Jan 16, 2022 at 6:12 AM Kit <kit.saels@gmail.com> wrote:
>>
>> Computer memory space is not important today. The place on the screen
>> is more important if one reads or edits such structured text.
>> --
>> Kit
>>
>> ne 16. 1. 2022 v 2:54 odesílatel Dimitre Novatchev
>> <dnovatchev@gmail.com> napsal:
>> > Personally,  I am trying to use whenever possible attributes over elements, due to a "minor", boring reason: attributes take much less space in memory (and in written form) than elements, and this can lead to significant memory footprint difference and performance difference for big documents.
>> >
>> > Thanks,
>> > Dimitre

_______________________________________________________________________

XML-DEV is a publicly archived, unmoderated list hosted by OASIS
to support XML implementation and development. To minimize
spam in the archives, you must subscribe before posting.

[Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
subscribe: xml-dev-subscribe@lists.xml.org
List archive: http://lists.xml.org/archives/xml-dev/
List Guidelines: http://www.oasis-open.org/maillists/guidelines.php



--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.
 


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS