473,417 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,417 software developers and data experts.

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 6079
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 selectSingleNode, 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
getElementsByTagName e.g. you can replace
xmlDoc.selectNodes('//element-name')
with
xmlDoc.getElementsByTagName('element-name')
--

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

Martin Honnen ha scritto:
MSXML provides two methods, one called selectSingleNode, 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.implementation.hasFeature("XPath", "3.0") )
{
// prototying the XMLDocument
XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
{
if( !xNode ) { xNode = this; }
var oNSResolver = this.createNSResolver(this.documentElement)
var aItems = this.evaluate(cXPathString, xNode, oNSResolver,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
var aResult = [];
for( var i = 0; i < aItems.snapshotLength; i++)
{
aResult[i] = aItems.snapshotItem(i);
}
return aResult;
}
// prototying the Element
Element.prototype.selectNodes = function(cXPathString)
{
if(this.ownerDocument.selectNodes)
{
return this.ownerDocument.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
getElementsByTagName 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
getElementsByTagName 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 selectSingleNode, 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.implementation.hasFeature("XPath", "3.0") )
{
// prototying the XMLDocument
XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
{
if( !xNode ) { xNode = this; }
var oNSResolver = this.createNSResolver(this.documentElement)
var aItems = this.evaluate(cXPathString, xNode, oNSResolver,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
var aResult = [];
for( var i = 0; i < aItems.snapshotLength; i++)
{
aResult[i] = aItems.snapshotItem(i);
}
return aResult;
}
// prototying the Element
Element.prototype.selectNodes = function(cXPathString)
{
if(this.ownerDocument.selectNodes)
{
return this.ownerDocument.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
getElementsByTagName 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
getElementsByTagName 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.createRange();
range.selectNode(document.getElementById(id));
range.deleteContents();
}

</script>
<button onclick="foo('div0');">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.createRange();
range.selectNode(document.getElementById(id));
range.deleteContents();
}

</script>
<button onclick="foo('div0');">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.createRange();
range.selectNode(document.getElementById(id));
range.deleteContents();
}

</script>
<button onclick="foo('div0');">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.javascript 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_transform_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
J_Zanetti wrote:
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.createRange();
range.selectNode(document.getElementById(id));
range.deleteContents();
}

</script>
<button onclick="foo('div0');">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()?
I don't know, I don't know what you are trying to do - ranges are
useful for manipulating document fragments in ways that aren't
available using other DOM methods. I only suggested range.selectNode
because I thought you'd made a typo with "SelectNode".

As I understand it, you want to extract data from an XML document and
update the values of DOM elements. For that you can use common DOM
Core methods such as getElementsByTagName, getAttribute, nextSibling,
etc. that probably have wider support than other methods.
--
Rob

Jan 10 '07 #11
RobG ha scritto:
21. Does Safari support XSLT?

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.
Thank you all guys!
At the end i went to choose for rewriting my functions by using the DOM
object functions.
With getElementsByTagName and the data property, ive been able to get
data for the XML as i needed to do. So finally, my application works
fine in IE, Firefox and Safari too:)

Thanks again

Jan 11 '07 #12

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

Similar topics

14
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)...
4
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...
2
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...
1
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 =...
4
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...
5
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...
34
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
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
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.