Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can I detect XHTML in the XML DOM? Is that even what I want?

    For a script where it detects, and uses appropriate methods, so that it works on XHTML pages regardless of which DOM it's in.

    At the moment, I'm testing for document.createElementNS and document.styleSheets, but it's messy - Safari declares support for both but the DOM 2 CSS doesn't actually work ... IE supports document.styleSheets but it uses a proprietary rule syntax ... Opera 7 doesn't support that but it does support createElementNS.

    So instead of testing for support with named-browser exclusions, I thought maybe test for the XML DOM ... but then is it safe to assume that any JS-capable browser which is in the XML DOM supports the required methods?

    Or is this all bunk ... should I just be pragmatic and test for Gecko ..?
    Last edited by brothercake; 07-24-2003 at 07:41 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why not just test for method/property you are interested in?
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Agreed, that's how I handle createElementNS
    Code:
    document.createHTMLElement = function( elemName, attribs )
    {
        if ( document.createElementNS )
        {
            var elem = document.createElementNS( "http://www.w3.org/1999/xhtml", elemName );
            var isNamespaced = true;
        }
        else
        {
            var elem = document.createElement( elemName );
            var isNamespaced = false;
        }
        if ( typeof attribs != 'undefined' )
        {
            for ( var i in attribs )
            {
                switch ( true )
                {
                    case ( i == 'text' )  : elem.appendChild( document.createTextNode( attribs[i] ) ); break;
                    case ( i == 'class' ) : elem.className = attribs[i]; break;
                    default : 
                        if ( isNamespaced )
                        {
                            elem.setAttributeNS( "http://www.w3.org/1999/xhtml", i, '' );
                        }
                        else
                        {
                            elem.setAttribute( i, '' );
                        }
                        elem[i] = attribs[i];
                }
            }
        }
        return elem;    
    }
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah that's essentially what I'm doing now, but to save code in disparate places where one or the other method is needed, I wanted to set a global flag that means it understands both document.styleSheets and createElementNS

    What I'm currently do is this, and it works just fine:
    Code:
    udm.safari = (
    	navigator.vendor!='KDE'&&
    	typeof document.childNodes!="undefined"&&
    	typeof document.all=="undefined"&&
    	typeof navigator.taintEnabled=="undefined"
    	)?true:false;
    udm.xdom = (
    	typeof document.createElementNS!='undefined'&&
    	typeof document.styleSheets!="undefined"&&
    	!udm.safari
    	)?true:false;
    But it's not 100% reliable - because the Safari test is a hack that may not always work - and it doesn't allow for the possibility of future browsers which may, like Safari, declare support for both but not actually have a useable implementation.

    So I was thinking, if I *know* a document is in the XML DOM, it's near-as-dammit safe to assume it can support these methods.

    But thanks guys for your answers. I wouldn't mind knowing academically how to detect the DOM, but I guess it's not essential to know..
    Last edited by brothercake; 07-26-2003 at 09:36 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •