No announcement yet.

XML Data Direct Accessor

  • Filter
  • Time
  • Show
Clear All
new posts

  • XML Data Direct Accessor

    Hi everyone,

    JavaScript allows for direct filtering and accessing of data, without needing to use an iteration statement (for, for each), by using a dotted notation, such as:

    var m = != "silver").model

    Using the XML below, the above statement will return all of the "model" nodes of every parent "car" where the color is not silver.

    This dotted notation can't work with HL7 XML because there are dots all over the place in the node name. Either the dots needs to be escaped, which I haven't been able to do, or you have to try the bracketed notation, which doesn't seem to work either.

    Is there a way to do what I've done below with HL7 bracketed notation or a way to use the dotted notation by escaping the dots in node names?

    Sample XML which allows for dotted notation
    var x = new XML(

    Different tests:
    var m = == "silver").model;
    returns: <model>Civic</model><model>Jetta</model>

    var m = != "silver").model;
    returns: Focus

    var m = x['car'](['car']['color'] == "silver")['model'];
    throws error

    var m = x['car'].(['car']['color'] == "silver")['model'];
    returns nothing

    var m = x['car'].(['color'] == "silver")['model'];
    returns nothing

    Steve Metz

  • #2
    To clarify, that ".(foo == 'bar')" syntax is part of E4X, not JavaScript itself.

    You can use a function in there:

    var m ={return new XML(this)['color'] == 'silver'}()).model;
    Last edited by narupley; 03-04-2016, 08:15 AM.
    Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

    Nicholas Rupley
    Work: 949-237-6069
    Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.

    - How do I foo?
    - You just bar.


    • #3
      Thanks. Works perfectly.