By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,655 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

XML validation with parseFromString on Safari

P: n/a
jul
Hi,

When I use parseFromString on Firefox or loadXML on Internet Explorer,
I can know if it's a valid xml content but when I use parseFromString
on Safari, I get a part of the content until it's invalid but I can't
know if the content is valid or not.

Someone has any idea ?

Thanks

Julien
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
pr
jul wrote:
When I use parseFromString on Firefox or loadXML on Internet Explorer,
I can know if it's a valid xml content but when I use parseFromString
on Safari, I get a part of the content until it's invalid but I can't
know if the content is valid or not.

Someone has any idea ?
Unless I've missed something, Firefox's DOMParser doesn't validate XML
against a DTD or schema, so I'm thinking you mean 'well-formed' rather
than 'valid'.

In the case of both Firefox and Safari, you can determine whether a
string parsed successfully by the presence of a <parsererrorelement in
the resulting XML document. They differ about where you find it and what
namespace it is in, yet you can still do something simple like this:

var s, x, p = new DOMParser();
s = "<my-xml>" +
"<ok>content</ok>" +
"<rubbish>&</rubbish>" +
"</my-xml>";
// & is an error - remove it to make result OK

x = p.parseFromString(s, "text/xml");

alert(x.getElementsByTagName("parsererror").length ?
"xml error" : "ok!");
You could use x.evaluate() in place of x.getElementsByTagName().
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.