Internet Explorer "conditional compilation is turned off"

S

SteveYoungTbird

I apologize if this is slightly of topic, please feel free not to answer
it if you feel that it is.

I have been using the BadgerFish convention to translate an XML document
into a JSON object. The convention rules are here
http://badgerfish.ning.com/ and they are summarized below:

The Rules
* Element names become object properties
* Text content of elements goes in the $ property of an object.
* Nested elements become nested properties
* Multiple elements at the same level become array elements.
* Attributes go in properties whose names begin with @.
* Active namespaces for an element go in the element's @xmlns property.
* The default namespace URI goes in @xmlns.$.
* Other namespaces go in other properties of @xmlns.
* Elements with namespace prefixes become object properties, too.

This works perfectly in Firefox but because the namespaces go in
properties of @xmlns, IE6 throws a "conditional compilation is turned
off" error when working with the resulting JSON object. It doesn't like
the "@".

I googled around and found a possible solution at
http://msdn.microsoft.com/en-us/library/5y5529x3(VS.71).aspx which
suggests adding /*@cc_on @*/ to the beginning of the code. I have tried
this and now it still works in Firefox but gives a "Expected identifier"
error in IE6.

Here are links to two scripts, one with /*@cc_on @*/ at
http://members.chello.at/stephen.joung/testsite/indexJSON_ShowProperties1.html
and one without at
http://members.chello.at/stephen.joung/testsite/indexJSON_ShowProperties1.html

The file test is a straightforward JSON file without namespaces and
test4 has namespaces. Both scripts work in FF but give the errors
mentioned above in IE6

So I have two questions:

1) Can Badgerfish converted JSON with namespaces be used with IE? if so how?
2) Is there another method of converting XML to JSON which can deal with
namespaces known to and recommended by the experienced people in c.l.j.?

Thanks for any assistance,

Steve.
 
D

David Mark

I apologize if this is slightly of topic, please feel free not to answer
it if you feel that it is.

Any post can be freely ignored; but for those that are OT, perhaps a
reader could tell you where they would be on topic.
I have been using the BadgerFish convention to translate an XML document
into a JSON object. The convention rules are herehttp://badgerfish.ning.com/and they are summarized below:

The Rules
     * Element names become object properties
     * Text content of elements goes in the $ property of an object..
     * Nested elements become nested properties
     * Multiple elements at the same level become array elements.
     * Attributes go in properties whose names begin with @.
     * Active namespaces for an element go in the element's @xmlns property.
     * The default namespace URI goes in @xmlns.$.
     * Other namespaces go in other properties of @xmlns.
     * Elements with namespace prefixes become object properties, too.

Sounds dreadful.
This works perfectly in Firefox but because the namespaces go in
properties of @xmlns, IE6 throws a "conditional compilation is turned
off" error when working with the resulting JSON object. It doesn't like
the "@".

That isn't surprising. So use something else or refrain from
evaluating the JSON object (parse it instead.)
I googled around and found a possible solution athttp://msdn.microsoft.com/en-us/library/5y5529x3(VS.71).aspxwhich
suggests adding /*@cc_on @*/ to the beginning of the code. I have tried

Apparently you didn't read the article carefully. If you turn CC *on*
then those "@" characters will be treated as CC variables. Obviously
that won't help matters.
this and now it still works in Firefox but gives a "Expected identifier"
error in IE6.

Not unexpectedly.

[snip]
 
D

David Mark

Any post can be freely ignored; but for those that are OT, perhaps a
reader could tell you where they would be on topic.
Sounds dreadful.
That isn't surprising.  So use something else or refrain from
evaluating the JSON object (parse it instead.)
Apparently you didn't read the article carefully.  If you turn CC *on*
then those "@" characters will be treated as CC variables.  Obviously
that won't help matters.
Not unexpectedly.

Mr Marks, It would be a good thing if you didn't answer posts when you
have nothing positive to offer. I suppose my honest request for

You didn't see the answer to your question as a positive? What were
you looking for?
information will now deteriorate into a slanging match between you and
your "friends" and sensible users who might have had an answer to the

The question has been answered. What more is there to say?
actual questions posed will not want to get involved. This is what

For fear of what exactly?
usually happens when you get involved in a thread and it is really a
shame. Just go to, for example, Google Maps API group to see how it
could be, with highly respected "Gurus" that are extremely helpful.

LOL. I've seen their "Gurus" in action. Perhaps you should post your
question there (maybe you will get an answer you like better.)
I assume that you were not born with your knowledge of Javascript and

That's a good assumption as Javascript didn't exist at the time.
therefore you had to learn it and I expect you were allowed the luxury
of asking questions during the learning process. So why do you get so
worked up and angry at people that are only trying to learn
javascript?

Interesting take. Why do you get so defensive when people are only
trying to answer your question?

[snip]
 
S

SteveYoungTbird

David said:
Mr Marks, It would be a good thing if you didn't answer posts when you
have nothing positive to offer. I suppose my honest request for

You didn't see the answer to your question as a positive? What were
you looking for?
[snip]

Interesting take. Why do you get so defensive when people are only
trying to answer your question?

[snip]

I repeat the two questions I asked in the OP which you snipped from
your reply and which, despite what you claim, you haven't answered.

1) Can Badgerfish converted JSON with namespaces be used with IE? if so how?
2) Is there another method of converting XML to JSON which can deal with
namespaces which is known to and recommended by the experienced people
in c.l.j.?

Regards and Merry Christmas, Steve.
 
D

David Mark

David said:
[snip]
Mr Marks, It would be a good thing if you didn't answer posts when you
have nothing positive to offer. I suppose my honest request for
You didn't see the answer to your question as a positive?  What were
you looking for?
[snip]

Interesting take.  Why do you get so defensive when people are only
trying to answer your question?

I repeat the two questions I asked in the OP  which you snipped from
your reply and which, despite what you claim, you haven't answered.

The question I did answer is the one I had an answer for. Perhaps
somebody else will answer your other questions. Less than likely
after this tantrum though.

[snip]
 
S

SteveYoungTbird

David said:
David said:
[snip]
Mr Marks, It would be a good thing if you didn't answer posts when you
have nothing positive to offer. I suppose my honest request for
You didn't see the answer to your question as a positive? What were
you looking for? [snip]

Interesting take. Why do you get so defensive when people are only
trying to answer your question?
[snip]
I repeat the two questions I asked in the OP which you snipped from
your reply and which, despite what you claim, you haven't answered.

The question I did answer is the one I had an answer for. Perhaps
somebody else will answer your other questions. Less than likely
after this tantrum though.

[snip]

Please look at the original post and count the question marks. There
were only two questions, the rest was background information.

I also doubt that I will get any answers now and that is why I would
really appreciate it if you would refrain from replying to my posts in
future. Please!

Regards, Steve
 
D

David Mark

David said:
David Mark wrote:
[snip]
Mr Marks, It would be a good thing if you didn't answer posts when you
have nothing positive to offer. I suppose my honest request for
You didn't see the answer to your question as a positive?  What were
you looking for?
[snip]
Interesting take.  Why do you get so defensive when people are only
trying to answer your question?
[snip]
I repeat the two questions I asked in the OP  which you snipped from
your reply and which, despite what you claim, you haven't answered.
The question I did answer is the one I had an answer for.  Perhaps
somebody else will answer your other questions.  Less than likely
after this tantrum though.

Please look at the original post and count the question marks. There
were only two questions, the rest was background information.

Background information that led to a simple answer to your problem,
rendering the explicitly asked questions needless.
I also doubt that I will get any answers now and that is why I would

Why would that be?
really appreciate it if you would refrain from replying to my posts in
future. Please!

Do you really think I will remember your name in an hour?

[snip]
 
S

SteveYoungTbird

David said:
David said:
David Mark wrote:
[snip]
Mr Marks, It would be a good thing if you didn't answer posts when you
have nothing positive to offer. I suppose my honest request for
You didn't see the answer to your question as a positive? What were
you looking for?
[snip]
Interesting take. Why do you get so defensive when people are only
trying to answer your question?
[snip]
I repeat the two questions I asked in the OP which you snipped from
your reply and which, despite what you claim, you haven't answered.
The question I did answer is the one I had an answer for. Perhaps
somebody else will answer your other questions. Less than likely
after this tantrum though.
[snip]
Please look at the original post and count the question marks. There
were only two questions, the rest was background information.

Background information that led to a simple answer to your problem,
rendering the explicitly asked questions needless.
What simple answer to what problem? I want to convert XML (with
namespaces) to JSON, where do you show me how to do that?
Why would that be?

Because you have snipped the questions for one.
Do you really think I will remember your name in an hour?
What if I wrote "replies from D.Mark not wanted" at the top of my posts? ;-)


Regards,

steve.
 
D

David Mark

David said:
David Mark wrote:
David Mark wrote:
[snip]
Mr Marks, It would be a good thing if you didn't answer posts whenyou
have nothing positive to offer. I suppose my honest request for
You didn't see the answer to your question as a positive?  What were
you looking for?
[snip]
Interesting take.  Why do you get so defensive when people are only
trying to answer your question?
[snip]
I repeat the two questions I asked in the OP  which you snipped from
your reply and which, despite what you claim, you haven't answered.
The question I did answer is the one I had an answer for.  Perhaps
somebody else will answer your other questions.  Less than likely
after this tantrum though.
[snip]
Please look at the original post and count the question marks. There
were only two questions, the rest was background information.
Background information that led to a simple answer to your problem,
rendering the explicitly asked questions needless.

What simple answer to what problem? I want to convert XML (with
namespaces) to JSON, where do you show me how to do that?
Why would that be?

Because you have snipped the questions for one.

In my replies? So what?
What if I wrote "replies from D.Mark not wanted" at the top of my posts? ;-)

Unlikey to have the desired effect.

[snip]
 
T

Thomas 'PointedEars' Lahn

Owen said:
Part of the problem is that that is not the problem you are facing. It
seems that you have a valid JSON text generated from the XML but it is
not a valid JavaScript Object literal.

You are mistaken.
The solution was terse and without an explanation of why but this is
where:



The character '@' is not permitted in Javascript property names. This
one of a number of cases where a valid JSON text is not a valid
JavaScript object literal and so cannot simply be evaluated.

As David has explained already, that is _not_ the reason why. The problem
is caused instead by proprietary extensions of ECMAScript found in Microsoft
JScript that make syntax have special meaning when the proprietary feature
of Conditional Compilation is enabled.

<http://msdn.microsoft.com/en-us/library/7kx09ct1(VS.80).aspx>

While it is correct that '@' must not be the prefix of an ECMAScript
identifier, it may be the prefix of a property name; property names are
stored as strings, and so may begin with and contain *any* Unicode character
(which makes ECMAScript objects ultimately useful as a dictionary). IOW,

{@foo: "bar"}

is syntactically incorrect, while

{"@foo": "bar"}

is correct. In particular, because JSON quite wisely requires all property
names to be quoted, this is _not_ an issue with JSON per se:

<http://json.org/>

It only becomes an issue with JScript and Conditional Compilation being enabled.
The solutions:
- use some prefix other than '@'
- use a parser that understands the full JSON syntax

Those are solutions for another problem.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
You are mistaken.

It is apparently not a valid *JScript* Object literal, see below.
As David has explained already, that is _not_ the reason why. The problem
is caused instead by proprietary extensions of ECMAScript found in Microsoft
JScript that make syntax have special meaning when the proprietary feature ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
of Conditional Compilation is enabled.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Strike the last part. I read the error message again and it occured when
Conditional Compilation was _not_ enabled. So this would only always be an
issue with JScript, no matter the enabled state of its Conditional
Compilation feature. Insofar you are partially correct, and the solution to
this problem is to not use the `@' or to parse the string if there is no way
to let the script engine ignore the `@' but include it in the property name.

PointedEars
 
J

Jorge

So it seems that you are correct and the Badgerfish JSON output is
suspect.

Thanks for your help. Steve.

Nope, that JSON text is 100% allright. Do an eval('('+jsonTxt+')');,
instead of eval(jsonTxt);...
 
T

Thomas 'PointedEars' Lahn

Richard said:
[...]
However, changing the above by adding double quotes around the 'name' in
the name/value pair to give:-

[...]
var x = {
"@somthing":"1"
};
[...]

- and IE 6 no longer has a problem; no errors are reported. JScript
apparently does not look inside string literals for occurrences of the
'@' symbol (at least no when CC is already 'off').

That's a relief, thanks. (I switched back to GNU/Linux recently -- WLAN
finally working! -- and thus could not test JScript myself as ies4linux
failed to install as of yet.)


Merry Christmas,

PointedEars
 
S

SteveYoungTbird

Owen said:
I think you will find that IE is complaining about the line
var contents = eval(varname);
in your 'look' function for some values of 'varname'. I would expect
there to be problems in the cases where the object property names are
neither integers nor valid identifiers given the way in which 'varname'
is constructed. IE appears to be seeing something it interprets as
containing conditional complation for some values of 'varname'.

But what?

I have tidied up the script a bit and have included as default a version
of the BookCatalogue.xml in JSON format that works and doesn't give any
errors in Firefox/Firebug but gives the "conditional compilation is
turned off" error in IE6.

The script is at
http://members.chello.at/stephen.joung/testsite/indexJSON_ShowProperties5.html
and the JSON file at
http://members.chello.at/stephen.joung/testsite/test10.json

Thanks, Steve.
 
S

SteveYoungTbird

Owen said:
But what?

I have tidied up the script a bit and have included as default a version
of the BookCatalogue.xml in JSON format that works and doesn't give any
errors in Firefox/Firebug but gives the "conditional compilation is
turned off" error in IE6.

The script is at
http://members.chello.at/stephen.joung/testsite/indexJSON_ShowProperties5.html
and the JSON file at
http://members.chello.at/stephen.joung/testsite/test10.json

Look at the output when you run it with Firefox.

The second line under the button is:
data.BookCatalogue.Book[0].Title.@xmlns.$ = http://www.publishing.org

When that line was constructed, 'varname' must have had the value
"data.BookCatalogue.Book[0].Title.@xmlns.$" and that string was passed
as the argument to eval.

When using the dot notation the property name must be a valid identifier
and '@xmlns' is not a valid identifier.

Try replacing your loadJSON function with this:

function loadJSON() {
data = ( {"@x": "y"} );
look("data");
}

IE will complain about conditional compilation. Firefox will apparently
silently allow the incorrect identifier syntax.

Fix your 'look' function so that it does not generate and then attempt
to evaluate syntactically incorrect expressions. The best approach would
be to not use 'eval' at all.

Hi Owen thanks for taking the time to help with this.

If I understand correctly what you are saying, then JScript cannot
evaluate JSON translated according to the Badgerfish convention because
@xmlns is not a valid identifier. However according to Badgerfish:

* Active namespaces for an element go in the element's @xmlns property.

Now, parsing JSON kind of defeats the object (pun intended) and so I
come back to the original two questions from my OP:

1) Can Badgerfish converted JSON with namespaces be used with IE? if so how?
2) Is there another method of converting XML to JSON which can deal with
namespaces known to and recommended by the experienced people in c.l.j.?

Regards, Steve
 
S

SteveYoungTbird

Thanks to Toby A Inskster at the JSON Schema Newsgroup I have fixed the
problem. In short the "look" function tried to access
properties using the obj.prop syntax, rather than obj["prop"] syntax and
IE didn't like that. If you are interested the full answer is here
http://groups.google.com/group/json-schema/browse_thread/thread/8fcedf6537b409a8

I have corrected the script accordingly and it now works in both FF and
IE. You can check it for yourselves at
http://members.chello.at/stephen.joung/testsite/indexJSON_ShowProperties7.html

Many thanks to all who participated in trying to find a solution, I am
very grateful.

Regards, Steve.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top