XML validation with parseFromString on Safari

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jul

    XML validation with parseFromString on Safari

    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
  • pr

    #2
    Re: XML validation with parseFromString on Safari

    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 <parsererrorele ment 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>conten t</ok>" +
    "<rubbish>& </rubbish>" +
    "</my-xml>";
    // & is an error - remove it to make result OK

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

    alert(x.getElem entsByTagName(" parsererror").l ength ?
    "xml error" : "ok!");


    You could use x.evaluate() in place of x.getElementsBy TagName().

    Comment

    Working...