Validating XML as it is being received over a Java TCP server socket

Posted on 2011-10-05
Last Modified: 2012-06-21
Hi all,
I should start off by saying that I am transitioning to Java from other languages (C/C++, C#) so I am not familiar with much of the existing functionality that is inherent to the Java language, or the many libraries that have been written to supplement functionality that is not built into the core code.  

I have a Java ServerSocket which will be receiving XML messages.  The fundamental question I have is - how do I know if and when I have received the whole XML message?  

If there were a way to ensure that in every case the XML message would arrive intact without timeouts or in transit errors then the task would be as simple as looking for the closing root tag, but this is, obviously not the real world.

So the different possible problems that I can see arising are:

* The client stalls and stops sending data.  This is easily handled by setting a timeout on the socket.
* The client sends an invalid XML message.
* The client sends a valid XML message, but does not conform to an XML message that the application does not know how to process (i.e. doesn't conform to a DTD or XSD)

So the though I have as to how to handle these scenarios is to write the incoming data to a stream which can validate the XML as it arrives for immediate problems, will recognize when the XML message is complete, and will validate it against a DTD or XSD.

Does such an animal already exist, or is there a ready way to develop such a thing?
Question by:edc
    LVL 20

    Accepted Solution

    LVL 1

    Author Closing Comment

    Thank you amit_n_panchal.  There was an implementable idea in one of the links regarding sending a token after the message which will give the code a specific token to key on when it sees it in the stream.

    Some things are just too obvious when you are well down into the details. :o)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Suggested Solutions

    Title # Comments Views Activity
    Multiple issues with Java 14 37
    XML namaspace 2 27
    array6 challenfge 6 48
    allStar challenge 1 27
    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    The viewer will learn how to implement Singleton Design Pattern in Java.
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now