P
Pavils Jurjans
Hello,
I have been developing an Ajax-style framework for couple of years now.
Now I am reworking some parts of it. The problem was that I used to use
JSON for JavaScript value serialization/deserialization, but this
approach has some limitations when it comes to large data - the
JavaScript at the client side has too much load working with it. So, I
thought, I'd rework the serialization to XML format.
The idea is short-as-possible bare-bones serialization:
For boolean values:
<bool value="true"/>
For numeric values:
<num value="1234.567"/>
For string values:
<str value="ABC"/>
For arrays:
<arr>
<bool index="0" value="true"/>
<num index="1" value="777"/>
<str index="2" value="abc"/>
</arr>
For objects:
<obj>
<bool key="dataFieldA" value="true"/>
<num key="dataFieldB" value="777"/>
<str key="dataFieldC" value="abc"/>
</obj>
For classes:
<obj class="Person">
<str key="name" value="John Smith"/>
<str key="age" value="30"/>
</obj>
etc. You can see where I am landing.
The problem I am stuck with is that in JavaScript, you can have
perfectly legal string with fancy charcodes:
var str = String.fromCharCode(7);
The problem is that the following XML does not validate:
<str value=""/>
You can test this out online (MSIE):
http://www.jurjans.lv/dhtml/XMLparse.html
Right now, it seems that the only exit is to have another layer of
encoding/decoding, handled by JavaScript, when building.parsing the XML
data, something like
<str value="\x07"/>
It makes me somewhat sad, because it brings back to having
JavaScript-based string encoding/decoding (ie, using string.replace),
that might be time and load consuming when doing large strings.
Maybe someone has good ideas how to handle these special charcode
values?
Regards,
Pavils
I have been developing an Ajax-style framework for couple of years now.
Now I am reworking some parts of it. The problem was that I used to use
JSON for JavaScript value serialization/deserialization, but this
approach has some limitations when it comes to large data - the
JavaScript at the client side has too much load working with it. So, I
thought, I'd rework the serialization to XML format.
The idea is short-as-possible bare-bones serialization:
For boolean values:
<bool value="true"/>
For numeric values:
<num value="1234.567"/>
For string values:
<str value="ABC"/>
For arrays:
<arr>
<bool index="0" value="true"/>
<num index="1" value="777"/>
<str index="2" value="abc"/>
</arr>
For objects:
<obj>
<bool key="dataFieldA" value="true"/>
<num key="dataFieldB" value="777"/>
<str key="dataFieldC" value="abc"/>
</obj>
For classes:
<obj class="Person">
<str key="name" value="John Smith"/>
<str key="age" value="30"/>
</obj>
etc. You can see where I am landing.
The problem I am stuck with is that in JavaScript, you can have
perfectly legal string with fancy charcodes:
var str = String.fromCharCode(7);
The problem is that the following XML does not validate:
<str value=""/>
You can test this out online (MSIE):
http://www.jurjans.lv/dhtml/XMLparse.html
Right now, it seems that the only exit is to have another layer of
encoding/decoding, handled by JavaScript, when building.parsing the XML
data, something like
<str value="\x07"/>
It makes me somewhat sad, because it brings back to having
JavaScript-based string encoding/decoding (ie, using string.replace),
that might be time and load consuming when doing large strings.
Maybe someone has good ideas how to handle these special charcode
values?
Regards,
Pavils