Hybrid View

  1. #1
    Ext JS Premium Member
    Join Date
    May 2007
    Posts
    46
    Vote Rating
    1
    fshort is on a distinguished road

      0  

    Default xml namespaces with Ext.DomQuery

    xml namespaces with Ext.DomQuery


    Hi,
    I have an xml document which contains element names consisting of namespaces, i.e.:

    <cam:Alertcode>3000</cam:AlertCode>

    I'd like to use the DomQuery class to select this node from the document but it throws an error:

    Code:
     Ext.DomQuery.pseudos[name] is not a function.
    The command I'm using to do the select is

    Code:
    Ext.DomQuery.selectNode("cam:AlertCode", doc.firstChild);
    Is there a way to use DomQuery to select elements who's name contains a namespace reference?
    Last edited by mystix; 29 Nov 2007 at 6:42 PM. Reason: moved to 1.x Help from 1.x Bugs

  2. #2
    Ext User
    Join Date
    Jan 2008
    Location
    Paris (Les Lilas)
    Posts
    4
    Vote Rating
    0
    Hadrien is on a distinguished road

      0  

    Default


    I you want to use xml namespaces with DomQuery you have to modify a little bit the source code :

    replace
    Code:
    var tagTokenRe = /^(#)?([\w-\*]+)/;
    by
    Code:
    var tagTokenRe = /^(#)?([\w-\*]+:?[\w-\*]+)/
    and
    Code:
    re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
    select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
    by
    Code:
    re: /^(?:([\[\{])(?:@)?([\w-:]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
    [\]\}])/,
    select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
    add
    Code:
    var namespaceRe = /^([\w]+:)?([\w-\*]+)/;
    just after
    Code:
    var tagTokenRe = /^(#)?([\w]+:?[\w]+|\*)/;
    and thus modify

    Code:
            if(!mode){
                for(var i = 0, ni; ni = ns[i]; i++){
                    cs = ni.getElementsByTagName(tagName);
                    for(var j = 0, ci; ci = cs[j]; j++){
                        result[++ri] = ci;
                    }
                }
    like this

    Code:
            if(!mode){
                for(var i = 0, ni; ni = ns[i]; i++){
                    cs = ni.getElementsByTagName(tagName.match(namespaceRe)[2]);
                    for(var j = 0, ci; ci = cs[j]; j++){
                        result[++ri] = ci;
                    }
                }
    You can ask me by PM if I'm not clear.

    Is a modification is planned for this problem ?

    Because with ns, DomQuery is so amazing

    EDIT :

    I realized that selectValue didn't work, to correct edit ext-all-debug like this :

    Code:
    		re: /^@([\w-]+:?[\w-]+)/,
    //              re: /^@([\w-]+)/,
                    select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'

  3. #3
    Sencha User
    Join Date
    Feb 2011
    Posts
    18
    Vote Rating
    0
    wdonne is on a distinguished road

      0  

    Default This can't work

    This can't work


    This approach lets you search for names with namespace prefixes, but not namespaces. Throughout a document the same namespace can be used with different prefixes. The DOM API should be level 2 and for the additional selector-based query functions it should be possible to declare the prefixes for the namespaces that will be used in the selectors. Those prefixes are not related to those in the XML document.

    Werner Donné.

  4. #4
    Sencha User
    Join Date
    May 2009
    Posts
    136
    Vote Rating
    5
    DiscoBoy is on a distinguished road

      0  

    Default


    Bah, I'm really dissapinted. This still doesn't work with ExtJS 4.X
    I must say this is shameful!

  5. #5
    Ext User
    Join Date
    Jan 2009
    Location
    Russian
    Posts
    5
    Vote Rating
    0
    smails is on a distinguished road

      0  

    Default


    Thank you very much for the information at this time it works

  6. #6
    Ext User
    Join Date
    Jan 2009
    Location
    Russian
    Posts
    5
    Vote Rating
    0
    smails is on a distinguished road

      0  

    Default


    When using the modified class are not working class library ExtJS. But I created a class Ext.nsDomQueryYu in which the modification and use it for their needs. A class Ext.DomQuery using library classes.

  7. #7
    Ext User
    Join Date
    Jan 2009
    Posts
    7
    Vote Rating
    0
    velislav is on a distinguished road

      0  

    Default Changes failed

    Changes failed


    I'm trying to fulfill instructions. But

    Code:
    re: /^(?:([\[\{])(?:@)?([\w-:]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
    [\]\}])/,
    select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
    raises error in EXTJS.
    Would you post the whole source as attachment?

  8. #8
    Ext User
    Join Date
    Jan 2009
    Location
    Russian
    Posts
    5
    Vote Rating
    0
    smails is on a distinguished road

      0  

    Default


    Code:
    re: /^(?:([\[\{])(?:@)?([\w-:]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
    [\]\}])/,
    select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
    Syntax error. Try this:
    Code:
    re: /^(?:([\[\{])(?:@)?([\w-:]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
    select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
    But with these changes, the library ExtJS does not work. I created a
    separate class for working with namespaces. Full source file
    ext-all-debug.js as an attachment.
    Attached Files

  9. #9
    Sencha User
    Join Date
    Mar 2008
    Location
    France
    Posts
    56
    Vote Rating
    0
    Gordon25 is on a distinguished road

      0  

    Default


    I have the same problem, I downloaded your version of ext-all-debug.js and
    I put in my html file:

    Code:
    <script type="text/javascript" src="../../ext-all.js"></script>
    by

    Code:
    <script type="text/javascript" src="../../ext-all-debug.js"></script>
    but it does not