× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: HTML to XML, vice versa
  • From: "Stone, Brad V (TC)" <bvstone@xxxxxxxxxxxxxx>
  • Date: Tue, 13 Mar 2001 15:15:41 -0600

> A static method might work well in simple cases:
> 
> public class XMLWrapper  {
> 
>     public static String toXML(String tag,String contents) {  
>  return  "<"
> +tag+">"+
>             contents+"</"+tag+">"; };
> 
> };

Then wouldn't I have to do something like:

out.println(new XMLWrapper.toXML(myClassList.getField(i).status,"status"));

> 
> The static method "toXML" functions like a procedural method for
> simple things.
> 
> However, especially where XML attributes are involved, the
> static method could be foregone in favor of a more robust
> O-O approach.  I know you said "I don't want to do this" but it is
> a proper O-O method and it has its advantages.  Let's check it out.

How is the following example any more OO than the first?  Because it extends
another object?  But that object is "procedural"?  If not, it doesn't look
much different.  What make it more OO?

> 
> Let's take the familiar HTML tag "TD" and render a subset of 
> it as if it
> were an XML tag:
> 
> public class XMLTDWrapper extends XMLWrapper {
> 
>    String align;
>    int wide;
>    String pcdata;
> 
>     public XMLTDWrapper(String alignment, int width, contents) {
>          align=alignment;
>          wide=width;
>          pcdata = contents;
>     }
> 
>    public String toString() {
>          // for performance, you may want to use StringBuffer and
>          // strinbuff.append() to build this up rather than all this +
> stuff.
>         return "<TD align=\""+align+"\" width=\""+wide+"\" >"+
>              pcdata + "</TD>";
>    }
> }
> 
> Even for simpler cases, the real O-O version is probably a 
> better approach
> than the first (especially as in real XML, attributes might be defined
> later
> and the real O-O structure allows them to be readily added).
> 
> In the true O-O case, you don't even have to declare a
> XMLTDWrapper object reference.  A little judicious syntax 
> will enable you
> to get the result you want all in one step:
> 
> String outputstuff = otherstuff +
>    (new XMLTDWrapper(alignment,width,contents)).toString();

But see, Im having a hard time with it because the alignment, width and
contents fields are all really something nasty looking.  So, it would look
something like this:

String outputstuff = otherstuff +
    (new XMLTDWrapper(myClassList.getField(i).status.alignment,
                      myClassList.getField(i).status.width,
                      myClassList.getField(i).status.data)).toString();

Which means I have to subset "MyClass" yet again to include attributes of
each field from the field (when before .status simply contained the data
itself).  Makes it even more harder to follow.  

I think it's cool, but would I want to do a whole system like this?  Yikes!
This system I'm working on now is just 1/100000th of the entire system.  

Am I alone in what I'm thinking?  I know I'm wet behind the ears, and I want
to (and will) go deeper, but man.  This is a lot of work for a "real"
application.

Brad
+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.