Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Sep 2006
    Posts
    8
    Member #
    13895
    I'm in the process of writing an ajax framework, and I've come to a point now where i need to define how a response from the server should look like. Naturally, this is very easy by writing a document type definition for the xml that will be coming from the server. The text editor I use, jEdit, is very cool because it will validate the xml on the fly if there is a dtd specified in it, but I am left wondering at what point does the browser validate the xml, if ever?

    I guess some of my confusion sets in because from what research i've done, there is a difference between parsing the xml based on the rules specified in the dtd, and actually validating it, even though I would think they would be one in the same. For example, microsofts XML parser can be explicitly told to validate xml against a dtd, while mozilla and opera do not support the ability to validate xml according to what ive read. This is using the xml parser via javascript, so I don't know if the same holds true when a browser is directly accessing an xml file and rendering it.

    Anyone have any insight as to how the browser handles a DTD? Some clarification would be great.

    Thanks

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    The browser mostly doesn't handle the DTD, as far as I know, and Javascript XML parsers probably don't, either. Too much overhead, as it were. But then, why do you want to validate on the client side? Validation is more to make sure for yourself that stuff is well-formed.

    Also, consider not using XML for AJAX responses. XML is really really inefficient. JSON is a much better solution, as it's not only less bandwidth-intensive, but also faster to parse.

  4. #3
    Junior Member
    Join Date
    Sep 2006
    Posts
    8
    Member #
    13895
    The DTD is used by the XML parser to determine how XML should be parsed. As I said earlier, I do not see how this differs from validation. DTD definition on wiki says this:
    A common misconception is that non-validating XML parsers are not required to read DTDs, when in fact, the DTD must still be scanned for correct syntax as well as for declarations of entities and default attributes. A non-validating parser may, however, elect not to read external entities, including the external subset of the DTD. If the XML document depends on declarations found only in external entities, it should assert standalone="no" in its XML declaration.
    This really only leaves me more confused, but I think I'm starting to find my answers.

    Concerning JSON, I used to be a big advocate of it myself. I've used it in a few AJAX apps and see a few blinding weaknesses compared to XML. They are alike in that you can have a hierarchial tree of properties and values, but there is one big difference. JSON is always interpreted the same way, but with XML, you define (via DTD) how the data is interpreted by the parser. Now, for a simple app this may not be a problem. Where I found its a problem is when dealing with character escaping. It can become hell with JSON. With XML, you can define whether the value of a property or element should be parsed at all. Also, a DTD, at least in theory, should automatically verify a well formed response. Not the case with JSON, you're just left hoping. As far as performance is concerned, it is neglegable. See http://www.crossedconnections.org/w/.../jsontest.html. There's a lot of hype surrounding JSON, but I really don't think its all that warranted.

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Well, there are a couple of aspects to this. First of all, performance tests on fairly small amounts of data aren't the smoothest. Second, I think there's a bigger advantage in bandwidth performance than in parsing performance.

    Now, I'll acknoweldge the advantage of a DTD in terms of validation. Assuming it's validated, of course, which I'm not sure whether it is or isn't -- but that has to add performance overhead.

    As for character escaping... JSON has a relatively small amount of characters to escape, and a well-designed wrapper class for JSON responses should take care of it with fair ease, I daresay.

    But the point is, it's mostly a matter of preference, and I was just curious where yours came from. Now I know :-)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:38 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com