substitute a variable with a string

Discussion in 'Javascript' started by jrough, May 25, 2011.

  1. jrough

    jrough Guest

    I have a question why doesn't this script substitute out for the alert
    line in the xmltostring function.
    I don't get an alert or substitution from the a= {b}. Thanks


    <html>
    <body>
    <script type = "text/javascript">
    var b= 'Best of luck "Studentname & Roll no" for your exam';
    var el = '<foo a={b}/>';
    alert(el.toXMLString());
    </script>
    </body>
    </html>
    jrough, May 25, 2011
    #1
    1. Advertising

  2. jrough

    jrough Guest

    On May 25, 1:20 am, Jake Jarvis <> wrote:
    Assumptions are dangerous :)
    I assumed E4X was Javascript and I could access it in my browser using
    my web server.
    That sounds like it was wrong. Do you mean I need a different doctype
    for Javascript with XML or something like that?
    If you have a web page I can read about this that would help.
    I thought EcmaJS whatever was the overall standard and Javscript was
    a flavor of it that pretty
    much followed that standard so I don't know how you mean to implement
    it or how you even know it is EcmajS
    but it does make sense that I need an xml
    file or something for this to work.
    > On 25.05.2011 01:34, wrote jrough:
    >
    > > I have a question why doesn't this script substitute out for the alert
    > > line in the xmltostring function.
    > > I don't get an alert or substitution from the a= {b}.  Thanks

    >
    > Check for errors then.
    >
    >
    >
    > > <html>
    > > <body>
    > > <script type = "text/javascript">
    > > var b= 'Best of luck "Studentname & Roll no" for your exam';
    > > var el = '<foo a={b}/>';

    >
    >            ^^^^^^^^^^^^^^
    >
    > That's a string, strings don't have
    > a toXMLString method.
    >
    > (I assume you actually are checking in an E4X supporting implementation)
    >
    > Use an XML initialiser
    >
    > | var el = <foo a={b} />;
    >
    > > alert(el.toXMLString());
    > > </script>
    > > </body>
    > > </html>

    >
    > --
    > Jake Jarvis
    jrough, May 27, 2011
    #2
    1. Advertising

  3. jrough

    RobG Guest

    On May 27, 10:09 am, jrough <> wrote:
    > On May 25, 1:20 am, Jake Jarvis <> wrote:
    > Assumptions are dangerous :)


    Please don't top-post, reply below trimmed quotes. Don't quote
    signatures or anything below them.

    > I assumed E4X was Javascript and I could access it in my browser using
    > my web server.


    Strictly, JavaScript is a trade mark of whoever bought it from Sun
    (probably Oracle I guess). It is the implementation of ECMAScript
    (ECMA-262), DOM APIs etc. in Netscape and Mozilla browsers.

    E4X is an extension to ECMAScript and is defined in ECMA-357. So a
    JavaScript (or any other implementation of ECMAScript) could include
    ECMA-357 if it wished. It has been implemented in Spidermonkey, which
    is the script engine in Firefox, but not made fully available by
    default (perhaps only for HTML documents).

    <URL: https://developer.mozilla.org/en/SpiderMonkey >


    > That sounds like it was wrong.


    Perhaps.

    >  Do you mean I need a different doctype
    > for Javascript with XML or something like that?


    It is intended to be used with XML documents, which should be valid in
    regard to their XML document declaration and DOCTYPE (if included).

    But you may be able to use it in HTML documents, according to the
    Mozilla E4X documentation:

    | In Gecko 1.8 based browsers such as Firefox 1.5,
    | E4X is already partially enabled for web page
    | authors. To fully enable E4X, the <script> element
    | needs to have the MIME type "text/javascript;e4x=1"

    <URL: https://developer.mozilla.org/en/e4x >

    > If you have a web page I can read about this that would help.
    > I thought EcmaJS whatever  was the overall standard and Javscript was
    > a flavor of it that pretty


    The language is ECMAScript, the standard is ECMA-262, the current
    edition is edition 5.

    <URL: http://www.ecma-international.org/publications/standards/Ecma-262.htm
    >


    JavaScript is one implementation of ECMAScript, there are many others.
    The word "javascript" or "Javascript" or "JavaScript" is often used to
    generically describe ECMAScript-based scripting environments used in
    web browsers and other hosts.


    > much followed that standard so I don't know how you mean to implement
    > it or how you even know it is EcmajS
    > but it does make sense that I need an xml
    > file or something for this to work.


    You could start with w3schools[1] but beware: much of what you learn
    there will not be strictly correct (sometimes plain wrong) but it will
    get you going. More authoritative but perhaps a bit harder to get
    going with is the Mozilla E4X documentation linked to above. Judging
    by the similarity between the tutorial and your posted code you may
    have already discovered it.

    1. <URL: http://www.w3schools.com/e4x/default.asp >


    --
    Rob
    RobG, May 27, 2011
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Richter
    Replies:
    5
    Views:
    713
    Steve Richter
    May 6, 2005
  2. Jeff Kish
    Replies:
    2
    Views:
    906
    Jeff Kish
    Nov 15, 2004
  3. Lingyun Yang
    Replies:
    2
    Views:
    488
    Daniel T.
    Apr 10, 2004
  4. Hans
    Replies:
    2
    Views:
    185
  5. MegaC
    Replies:
    3
    Views:
    468
    Brian Helterline
    May 24, 2004
Loading...

Share This Page