473,624 Members | 2,119 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading XML in Safari through selectNode

Hello everybody,

In my applications I've a ton of scripts that use remote XML file to
fill forms and evaluate contents; In these scripts I always use the
method SelectNode (that, with some workaround, works fine also in
Mozilla).
I've just found out that this method doesnt work in Safari browser,
therefore my applications are not usable by this browser.
Can anyone provide me any solution or workaround to be able to read XML
files in Safari wihout rewriting all of my scripts??

Thanks everyone :)

Jan 9 '07 #1
11 6094
J_Zanetti wrote:
In my applications I've a ton of scripts that use remote XML file to
fill forms and evaluate contents; In these scripts I always use the
method SelectNode (that, with some workaround, works fine also in
Mozilla).
Neither IE using MSXML nor Mozilla have any method called SelectNode
exposed on XML DOM objects.
MSXML provides two methods, one called selectSingleNod e, the other
called selectNodes. Are you using one of these?
I've just found out that this method doesnt work in Safari browser,
therefore my applications are not usable by this browser.
Can anyone provide me any solution or workaround to be able to read XML
files in Safari wihout rewriting all of my scripts??
I don't think Safari has XPath support so far thus if you really use
XPath expressions as arguments to that functions then you need to write
more code. For other simple tasks you might get away with using
getElementsByTa gName e.g. you can replace
xmlDoc.selectNo des('//element-name')
with
xmlDoc.getEleme ntsByTagName('e lement-name')
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 9 '07 #2

Martin Honnen ha scritto:
MSXML provides two methods, one called selectSingleNod e, the other
called selectNodes. Are you using one of these?
Thanks for answering Martin!
Yes, Im using selectNodes. Of course it works on IE, and in Mozilla
only if i add some code that redefine the working of this method; to be
precise, i add this code at the beginning of my script

if( document.implem entation.hasFea ture("XPath", "3.0") )
{
// prototying the XMLDocument
XMLDocument.pro totype.selectNo des = function(cXPath String, xNode)
{
if( !xNode ) { xNode = this; }
var oNSResolver = this.createNSRe solver(this.doc umentElement)
var aItems = this.evaluate(c XPathString, xNode, oNSResolver,
XPathResult.ORD ERED_NODE_SNAPS HOT_TYPE, null)
var aResult = [];
for( var i = 0; i < aItems.snapshot Length; i++)
{
aResult[i] = aItems.snapshot Item(i);
}
return aResult;
}
// prototying the Element
Element.prototy pe.selectNodes = function(cXPath String)
{
if(this.ownerDo cument.selectNo des)
{
return this.ownerDocum ent.selectNodes (cXPathString, this);
}
else{throw "For XML Elements Only";}
}
}

This doesnt work under Safari, since Xpath is not supported there; thus
should i write something similar for Safari? Honestly, i wouldnt know
where to start from...
I don't think Safari has XPath support so far thus if you really use
XPath expressions as arguments to that functions then you need to write
more code. For other simple tasks you might get away with using
getElementsByTa gName e.g. you can replace
Yes, I use xpath expressions as parameters for the selectNodes method
:(
So If i got it well, there are two options: rewriting my scripts with
getElementsByTa gName or redefining selectNodes. Which way do you think
is the best one?

Jan 9 '07 #3

Martin Honnen ha scritto:
MSXML provides two methods, one called selectSingleNod e, the other
called selectNodes. Are you using one of these?
Thanks for answering Martin!
Yes, Im using selectNodes. Of course it works on IE, and in Mozilla
only if i add some code that redefine the working of this method; to be
precise, i add this code at the beginning of my script

if( document.implem entation.hasFea ture("XPath", "3.0") )
{
// prototying the XMLDocument
XMLDocument.pro totype.selectNo des = function(cXPath String, xNode)
{
if( !xNode ) { xNode = this; }
var oNSResolver = this.createNSRe solver(this.doc umentElement)
var aItems = this.evaluate(c XPathString, xNode, oNSResolver,
XPathResult.ORD ERED_NODE_SNAPS HOT_TYPE, null)
var aResult = [];
for( var i = 0; i < aItems.snapshot Length; i++)
{
aResult[i] = aItems.snapshot Item(i);
}
return aResult;
}
// prototying the Element
Element.prototy pe.selectNodes = function(cXPath String)
{
if(this.ownerDo cument.selectNo des)
{
return this.ownerDocum ent.selectNodes (cXPathString, this);
}
else{throw "For XML Elements Only";}
}
}

This doesnt work under Safari, since Xpath is not supported there; thus
should i write something similar for Safari? Honestly, i wouldnt know
where to start from...
I don't think Safari has XPath support so far thus if you really use
XPath expressions as arguments to that functions then you need to write
more code. For other simple tasks you might get away with using
getElementsByTa gName e.g. you can replace
Yes, I use xpath expressions as parameters for the selectNodes method
:(
So If i got it well, there are two options: rewriting my scripts with
getElementsByTa gName or redefining selectNodes. Which way do you think
is the best one?

Jan 9 '07 #4
J_Zanetti wrote:
Hello everybody,

In my applications I've a ton of scripts that use remote XML file to
fill forms and evaluate contents; In these scripts I always use the
method SelectNode (that, with some workaround, works fine also in
Mozilla).
I've just found out that this method doesnt work in Safari browser,
therefore my applications are not usable by this browser.
Can anyone provide me any solution or workaround to be able to read XML
files in Safari wihout rewriting all of my scripts??
Post a minimal example or a link. Safari supports the selectNode
method as the following example shows:

<script type="text/javascript">

function foo(id) {
var range = document.create Range();
range.selectNod e(document.getE lementById(id)) ;
range.deleteCon tents();
}

</script>
<button onclick="foo('d iv0');">Remove div0</button>
<div id="div0">Here is div0</div>
--
Rob

Jan 9 '07 #5

RobG ha scritto:
J_Zanetti wrote:
Post a minimal example or a link. Safari supports the selectNode
method as the following example shows:

<script type="text/javascript">

function foo(id) {
var range = document.create Range();
range.selectNod e(document.getE lementById(id)) ;
range.deleteCon tents();
}

</script>
<button onclick="foo('d iv0');">Remove div0</button>
<div id="div0">Here is div0</div>
Thank you Rob!!
Here you seem to be using the methond selectNode of the objectRange
object.
In my scripts, I have only Document object; would it be enough to
define the Range for every document i have and then use its
selectNode()?
thanks :)

Jan 9 '07 #6

RobG ha scritto:
J_Zanetti wrote:
Post a minimal example or a link. Safari supports the selectNode
method as the following example shows:

<script type="text/javascript">

function foo(id) {
var range = document.create Range();
range.selectNod e(document.getE lementById(id)) ;
range.deleteCon tents();
}

</script>
<button onclick="foo('d iv0');">Remove div0</button>
<div id="div0">Here is div0</div>
Thank you Rob!!
Here you seem to be using the methond selectNode of the objectRange
object.
In my scripts, I have only Document object; would it be enough to
define the Range for every document i have and then use its
selectNode()?
thanks :)

Jan 9 '07 #7
VK
Reading XML in Safari through selectNodes

Safari has to become a browser yet before talking about any extensive
support. So far it is a rather rare case when buggy beta sketches being
distributed as final release two times in the row (Safari 1.x and
Safari 2.x) As I said in an older post I would understand it from any
Acme, Inc. but not from Apple.
Nightly builds of 3.0 are looking promising though: it seems that the
critics produced some effect and Apple is finally targeted to produce a
decent software product. I'm not saying "great" but at least "usable".

For the time being if Safari support is an absolute must then you can
try a library like ajaxslt:
<http://code.google.com/p/ajaxslt/>
former <http://sourceforge.net/projects/goog-ajaxslt/>

This is "the guy who made it" :-) - his project went from sourceforge
to Google, so copyright and license changed a bit in comparison with
the sourceforge stage. Still it remains free to use.

ajaxslt works with Safari 1.2 or higher because it is a "screw them
all" library. When Sarissa uses native XSLT tools of each browser,
whatever it can find, and then covers all differences and bugs under
one interface - ajaxslt-like libraries simply disregard any native XSLT
tools and implement them from the scratch by javascript means. This is
its power and weakness at the same time.
The power is because it is much easier to maintain and to extent. It
also make it really universal - with some modifications one could have
"XSLT" on Netscape 4.x
The weakness is because of lower level processing code they are using
top level javascript statements. This way you may get a noticeable
productivity impact depending on the kind and complexity of your
transformations .
Alas currently - until Apple starts to produce a usable browser - this
is the only option to support XSLT on Safari.

Jan 10 '07 #8
VK said the following on 1/10/2007 4:47 AM:
>Reading XML in Safari through selectNodes

Safari has to become a browser yet before talking about any extensive
support.
And you wonder why people say the things about you that get said.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 10 '07 #9
VK wrote:
[...]
For the time being if Safari support is an absolute must then you can
try a library like ajaxslt:
[...]
this is the only option to support XSLT on Safari.

21. Does Safari support XSLT?

Safari 1.3 and above supports XSL transformations of XML pages at load
time. XSLT support is limited to XSL page processing instructions
embedded at the top of an XML page:

<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl"
href="your_tran sform_file_here .xsl" ?>

XSLT not available via JavaScript for application to arbitrary XML in
an HTML page."
<URL: http://developer.apple.com/internet/....html#anchor21 >

It seemed to me that the OP was looking to use XML data to update the
content of DOM elements. For that, DOM 2 Core methods will do the job.

--
Rob

Jan 10 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
5773
by: DU | last post by:
According to a recent post, it seems that Konqueror 3.1+ and Safari 1.1 support CSS3 opacity style property under a proprietary name: "Support for the CSS3 opacity (using -khtml-opacity) property. Make entire blocks and inlines transparent without resorting to transparent PNGs." http://weblogs.mozillazine.org/hyatt/archives/2003_10.html#004249 Now, I have a demo page which works for MSIE 6 for Windows and Mozilla-based browsers but...
4
6010
by: Bernard | last post by:
Hi, I am suddenly getting Safari script errors with the following user agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.2 (KHTML, like Gecko) Safari/125.8 In a frameset scenario, the framesetting document (top) contains a
2
1978
by: jdlwright | last post by:
Hi, I have a big script that doesn't work in Safari 1.3, but does work in FF, and IE. I've given up going to my local Uni. to use their Macs (they've prevented the Debug menu from appearing after running that widely known hack), and so I want to buy my first Mac to do this properly. Being a PC person I am generally ignorant of Mac OS issues;
1
9285
by: Cheryl | last post by:
I have problems selecting the attribute when I use the SelectNode function. <book> <title store='7456' >Nutshell</title> <author id='1'>Drayton</author> <xauthor publish = "1" publishtime = "2"/> <author id='3'>Neward</author> <author id='2'>Albahari</author> </book>
4
2711
by: Paul W | last post by:
Hi - can someone point me to info on the issues/resolutions of supporting the safari browser? To help me understand, if I was developing pages in say FrontPage, what attributes would I set for 'target browser'? I'm having a helluva time with table layouts etc and goin' stir crazy.. Thanks, Paul.
5
2609
by: Bill Cohagan | last post by:
I'm having some serious difficulties with my ASP.Net 2.0 app rendering in Safari 2.0.3. The most immediate problem is that the menu control doesn't seem to work at all, particularly the use of dynamic levels. I've Googled around a bit and determined that the problem is not so much with Safari as it is with ASP.Net inaccurately determining the browser capabilites for that browser. In the 2.0 Framework it appears that browser caps are...
34
3823
by: Simon Wigzell | last post by:
document...focus() will scroll the form to move the specified text field into view on everything I have tried it with except Safari on the MAC. The form doesn't move. Any work around? Thanks.
3
5399
by: Jeff Paffett | last post by:
I'm trying to use the onPaste event in a text input, which according to Apple is supported. However, I get no response in Safari. Firefox works fine.
21
4395
by: Edward | last post by:
Hi All, I feel frustrated with one of my Customers who wants me to ensure that a dotnet web site I am building for them must be compatible to Apple's Safari browser! Safari is buggy and it does not support lots of things (xhtml etcc). However, what puzzles me is that there are some dotnet Framework 2 web sites out there that work perfectly well under Safari, whereas my website does not
0
8234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8172
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8620
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.