Expand my Community achievements bar.

javascript object as xml with attribute

Avatar

Level 2

Hello, I'm created javascript object for using SOAP Object for sends an XML Message to, a remote server from JavaScript. But I cannot create xml attribute. Do you know some construction for create JavaScript object representative xml element with attribute?

I tried for example:
var myObject = { myElement : "elementValue" };
// this is ok
<myElement>elementValue</myElement>

var myObject = { myElement : { myElement2 : "elementValue2" } }
// this is ok
<myElement>
  <myElement2>
    elementValue2
  </myElement2>
</myElement>

// when I tried some this
var myObject  = { myElement : { @myAttribute : "attributeValue" } }
// result was
<myElement>
  <@myAttribute>
    attributeValue
  </@myAttribute>
</myElement>

// but i need
<myElement myAttribute="attributeValue"></myElement>

Thank You very much.

5 Replies

Avatar

Former Community Member

var myElement = <myElement myAttribute="attributeValue"></myElement>;

app.alert(myElement.@myAttribute);

More info:http://en.wikipedia.org/wiki/ECMAScript_for_XML

By the way, can anyone tell me what happened to my user account? Since Sunday or Monday, all my private messages and post history have been wiped. If I browse the forums I see that my posts were created by the user 'c@tc.se-w1ZfAW'.

Serious stuff.

Was my account hacked?

Avatar

Level 10

Hi,

I doubt that your account was hacked. The Jive software sometimes throws a wobbly. Check out the general forum, where there are multiple threads on the topic.

                                  Why is my name 'LOsvSk' sound like lovesick.... (Updated)         ...

In any case it looks like you are already back to your normal self

Niall

Avatar

Former Community Member

I tried the logout-login-logout procedure with no luck. Still wiped with a zero'ed post count, and I have unread private messages that I can't get to.

Frustrating.

Thanks anyway.

Avatar

Former Community Member

I do not believe that the Designer JavaScript engine officially supports E4X. I could be wrong, however. You could use good old fashioned string manipulation.

// form1.page1.subform1.xml::calculate - (JavaScript, client)

var elementStr = "";

var attributeStr = "";

if (!(form1.page1.subform1.element.isNull)) {

  elementStr = form1.page1.subform1.element.rawValue;

}

if (!(form1.page1.subform1.attribute.isNull)) {

  attributeStr = form1.page1.subform1.attribute.rawValue;

}

this.rawValue = "<foo bar='" + attributeStr + "'>" + elementStr + "</foo>"; 

Steve

Avatar

Former Community Member

Hi Steve,

I think he should be safe. E4X has been part of SpiderMonkey's ECMAscript implementation since 1.6.0 (Adobe Reader officially supports E4X since version 8). The current engine (Acrobat 9) is currently on version 1.7-something. It's also described in the LC version of ActionScript.

If Adobe were to remove it all of a sudden, a lot of forms would break... :>