From df90308b0e40817b38273102f30a6ccc4f240809 Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Mon, 18 Aug 2014 14:10:36 -0400 Subject: [PATCH 1/4] use getElementsByTagNameNS for namespaced DZI xml when getElementsByTagName fails --- src/dzitilesource.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/dzitilesource.js b/src/dzitilesource.js index f5b75d69..1becfa4a 100644 --- a/src/dzitilesource.js +++ b/src/dzitilesource.js @@ -222,6 +222,7 @@ function configureFromXML( tileSource, xmlDoc ){ var root = xmlDoc.documentElement, rootName = root.localName, + ns = xmlDoc.documentElement.namespaceURI, configuration = null, displayRects = [], dispRectNodes, @@ -234,6 +235,11 @@ function configureFromXML( tileSource, xmlDoc ){ try { sizeNode = root.getElementsByTagName( "Size" )[ 0 ]; + // if finding by tag name failed, attempt to find with namespace + if (sizeNode === undefined) { + sizeNode = root.getElementsByTagNameNS(ns, "Size" )[ 0 ]; + } + configuration = { Image: { xmlns: "http://schemas.microsoft.com/deepzoom/2008", @@ -256,9 +262,15 @@ function configureFromXML( tileSource, xmlDoc ){ } dispRectNodes = root.getElementsByTagName( "DisplayRect" ); + if (dispRectNodes === undefined) { + dispRectNodes = root.getElementsByTagNameNS(ns, "DisplayRect" )[ 0 ]; + } for ( i = 0; i < dispRectNodes.length; i++ ) { dispRectNode = dispRectNodes[ i ]; rectNode = dispRectNode.getElementsByTagName( "Rect" )[ 0 ]; + if (rectNode === undefined) { + rectNode = dispRectNode.getElementsByTagNameNS(ns, "Rect" )[ 0 ]; + } displayRects.push({ Rect: { From 0d92737ff29e8b25d03c18820647e4b6ab265bc2 Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Mon, 18 Aug 2014 14:17:37 -0400 Subject: [PATCH 2/4] check length instead of undefined for DisplayRect nodes tagname ns fallback --- src/dzitilesource.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dzitilesource.js b/src/dzitilesource.js index 1becfa4a..8bb82406 100644 --- a/src/dzitilesource.js +++ b/src/dzitilesource.js @@ -262,7 +262,7 @@ function configureFromXML( tileSource, xmlDoc ){ } dispRectNodes = root.getElementsByTagName( "DisplayRect" ); - if (dispRectNodes === undefined) { + if (dispRectNodes.length === 0) { dispRectNodes = root.getElementsByTagNameNS(ns, "DisplayRect" )[ 0 ]; } for ( i = 0; i < dispRectNodes.length; i++ ) { From 343f9ed3674887f4362768cbe92dec32eb43a790 Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Mon, 18 Aug 2014 14:37:37 -0400 Subject: [PATCH 3/4] correct typo in fallback ns logic for pulling display rect nodes --- src/dzitilesource.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dzitilesource.js b/src/dzitilesource.js index 8bb82406..cc5fc5e1 100644 --- a/src/dzitilesource.js +++ b/src/dzitilesource.js @@ -263,7 +263,7 @@ function configureFromXML( tileSource, xmlDoc ){ dispRectNodes = root.getElementsByTagName( "DisplayRect" ); if (dispRectNodes.length === 0) { - dispRectNodes = root.getElementsByTagNameNS(ns, "DisplayRect" )[ 0 ]; + dispRectNodes = root.getElementsByTagNameNS(ns, "DisplayRect" ); } for ( i = 0; i < dispRectNodes.length; i++ ) { dispRectNode = dispRectNodes[ i ]; From fd0d8d4507beff74bcb3d0634940045a1f9bb943 Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Tue, 19 Aug 2014 13:47:51 -0400 Subject: [PATCH 4/4] always use getElementsByTagNameNS since it will work for DZI xml with or without ns prefix --- src/dzitilesource.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/dzitilesource.js b/src/dzitilesource.js index cc5fc5e1..eb283fab 100644 --- a/src/dzitilesource.js +++ b/src/dzitilesource.js @@ -234,11 +234,7 @@ function configureFromXML( tileSource, xmlDoc ){ if ( rootName == "Image" ) { try { - sizeNode = root.getElementsByTagName( "Size" )[ 0 ]; - // if finding by tag name failed, attempt to find with namespace - if (sizeNode === undefined) { - sizeNode = root.getElementsByTagNameNS(ns, "Size" )[ 0 ]; - } + sizeNode = root.getElementsByTagNameNS(ns, "Size" )[ 0 ]; configuration = { Image: { @@ -261,16 +257,11 @@ function configureFromXML( tileSource, xmlDoc ){ ); } - dispRectNodes = root.getElementsByTagName( "DisplayRect" ); - if (dispRectNodes.length === 0) { - dispRectNodes = root.getElementsByTagNameNS(ns, "DisplayRect" ); - } + dispRectNodes = root.getElementsByTagNameNS(ns, "DisplayRect" ); + for ( i = 0; i < dispRectNodes.length; i++ ) { dispRectNode = dispRectNodes[ i ]; - rectNode = dispRectNode.getElementsByTagName( "Rect" )[ 0 ]; - if (rectNode === undefined) { - rectNode = dispRectNode.getElementsByTagNameNS(ns, "Rect" )[ 0 ]; - } + rectNode = dispRectNode.getElementsByTagNameNS(ns, "Rect" )[ 0 ]; displayRects.push({ Rect: {