• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

When to parse a XML strings  RSS feed

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A little background. I've created an application using Java LiveConnect technology that receives an request (like an parts request) from a html page (using javascript) and sends the data to a backend database. The database finds all of the information about the part and sends it back to the javascript in the html page through the java applett. The program works just fine so I have no problems there. To make it short, when I send a request the argument looks like the following:
mom.send("<EXEC><PART>" + partnum + "</PART><LOCATION>" + loc + "</LOCATION><AVAIL>" + instock + "</AVAIL></EXEC>");
Note that my string I pass is an XML string. The data I receive back from the backend through the Java session it will look the same but all of the variable fields will be filled with data. Finally my question.
When would be the proper time to parse this XML string?
I could parse it using Java at the applett before I actually send it back to the javascript. Then instead of sending one large XML string to the html page, I could send back the XML arguments one at a time as I parse them. The second option would be to send the entire XML string to the Javascript embedded in the html and let the Javascript parse it. I would probably have to just use string functions to parse it at this level. The end result is I need to update fields that fill my html page by parsing the XML string at the Java level or Javascript level. Has anyone had to populate a html page using an XML string? The XML string may contain as much as 100+ arguments when passed back and forth if this makes a difference. Just asking for opinions here from anyone who may have done this and ran into any problems either way.
Joe Crew
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe,
IMHO the parsing and generation of HTML should be done on the Server - not by Javascript or the Applet running on the client. Parsing at times can be quite a resource extensive activity and doing it on the server makes your client(Applet) a lot lighter. Moreover if you only want to display 10 records out of 100 records that were fetched, parsing on the client would generate unnecessary traffic since you will be sending the extra 90 records to the client.
HTH

------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.
 
Joe Crew
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response. I don't think I can just parse on the server. I am very new to XML/DOM which is why I am posting. I am passing an XML string (not a file) to the server. Also this will actually be run on an embedded system not a PC or Internet connection. The XML string sent to the server (a request) is parsed so the server DB can search for the record. Only one record will ever be returned to the client but it may have as many as 100 fields associated with it. The DB sends the result of the request back through the applett to the html client requesting it. Once the applett or the client receives back from the server DB an XML string, I would think the parsing would occur at that time to display the results. Please tell me if I am wrong but I'm thinking that if we pass a single XML string containing 100 fields (though the average number of fields in a record would be more like 25) through the applett it would be faster than passing as many as 25 separate fields of an already parsed string.
 
Joe Crew
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a side question, once I receive the results of my XML string, be they already parsed or not, what would be the most efficient way to display the results. Note that I will not have access to XSL (because of the custom browser we are using). Also the "look and feel" of the html page that made the request will have to remain the same, ie, when the request is made the user will enter a part number. On that same html page will be numerous other fields that are blank. Once the results are received back from the server DB, I will now have to populate these previously blank fields. This is why the html page itself cannot change. In anyone's opinion, would the best way to fill these blank fields be with Javascript and accessing the DOM using, for example, an id associated with the field? Thank you.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are some observations -

  • You can parse an XML string just the way you parse an XML file. There is absolutely no different other than the sources being of different types( transient stream Vs. File on the hard disk. )
  • What is the purpose of parsing here?? Is it to filter out the unwanted fields from the XML result set?? If so you can keep a list of fields that you want to return to the client, parse on the server to remove the fields that are not required from the result XML stream, generate the HTML and return to the client.
    Reading your statements, I get a feeling the term "parsing" is being used in vague contexts.
  • Whether you want to display the result as an HTML or an Applet, I strongly discourage you from including the parsing logic on the client. It is way too expensive to have your applet bundled with parsers.
  • Consider passing a name-value pair result set (that is not an XML document) to the client instead of the XML document itself. This way you can still parse the resultset on the server, form the pseudo-resultset of the name-value pairs to include only what you want and push it to the client.

  • Hope that gives you something to think about..
    ------------------
    Ajith Kallambella M.
    Sun Certified Programmer for the Java�2 Platform.
    IBM Certified Developer - XML and Related Technologies, V1.
    [This message has been edited by Ajith Kallambella (edited April 25, 2001).]
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Warning: Micro$oft only!
I found this article a minute ago:
Communicate With the Server Using XMLHTTP http://gethelp.devx.com/techtips/xml_pro/10min/10min0899/10min0899.asp
�The .responseXML property (of XMLHTTP Request) returns the data sent back from the server as an XML entity. This can cut down significantly on using the XML document's .load method, because the XML will already have been downloaded and converted with .responseXML...�
Myself has no idea if it helps you or not, though...
 
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wrox has a free chapter from Professional Java XML Chapter 15: Client-Side Presentation Logic online. Looks cool...
 
Good night. Drive safely. Here's a tiny ad for the road:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!