SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Oct 2003
    Posts
    245
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Custom Markup Language (SAX parser)

    On Bebo, they use SNML (Social Network Markup Language) for application development.

    For example:

    Code:
    <sn:editor>
    This is text inside the editor.
    <sn:editor-heading>This is the heading</sn:editor-heading>
    </sn:editor>
    Output:

    Which will then output XHTML on the browser.

    I contacted Bebo, I asked how SNML (Social Network Markup Language) implemented.

    Reply from Bebo:
    A java based HTML ==> SAX parser (when a tag is recognized)

    Can you please explain how that work when tag is recognized and then convert to XHTML?
    [Home Sweet Home]

  2. #2
    SitePoint Wizard rozner's Avatar
    Join Date
    Oct 2002
    Location
    Paris
    Posts
    1,058
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well your sample code is just an XML document. The term SNML is just an XML file using the SNML schema or DTD. The reply from Bebo is pretty vague but based on it I would guess they're parsing the XML and generating the HTML output based on what they find. If it was me I would just do an XML/XSL transformation.

    Here are some SAX examples
    http://java.sun.com/developer/codesamples/xml.html#sax

  3. #3
    SitePoint Addict
    Join Date
    Oct 2003
    Posts
    245
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rozner View Post
    Well your sample code is just an XML document. The term SNML is just an XML file using the SNML schema or DTD. The reply from Bebo is pretty vague but based on it I would guess they're parsing the XML and generating the HTML output based on what they find. If it was me I would just do an XML/XSL transformation.

    Here are some SAX examples
    http://java.sun.com/developer/codesamples/xml.html#sax
    Here the full reply from Bebo:

    Snml is the following:
    1. A java based HTML ==> SAX parser
    2. Several hundred Java classes that are called when a tag is recognized
    3. Freemarker templates that are called by the above classes to produce the HTML that is then written out to the browser.


    Does that help?
    [Home Sweet Home]

  4. #4
    SitePoint Wizard
    Join Date
    Apr 2007
    Posts
    1,401
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    To me that's not very vague at all. I googled FreeMarker

    This sounds like exactly like what they said.

    Which part is vague to you?

  5. #5
    SitePoint Addict
    Join Date
    Oct 2003
    Posts
    245
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sg707 View Post
    To me that's not very vague at all. I googled FreeMarker

    This sounds like exactly like what they said.

    Which part is vague to you?
    I am not sure how the design work for SAX parser with FreeMarker.

    Let say you have:

    data.receive = <html> <head> <title> Blah Blah </title> </head> <sn:heading underline="true">This is the heading</sn:heading> </html>";
    SAX parser will try to find <sn:heading underline="true">

    when a tag is recognized from SAX parser, what happen next? how does it convert to HTML and then use FreeMarker ? I don't understand this part.
    [Home Sweet Home]

  6. #6
    SitePoint Wizard rozner's Avatar
    Join Date
    Oct 2002
    Location
    Paris
    Posts
    1,058
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sg707 View Post
    To me that's not very vague at all. I googled FreeMarker

    This sounds like exactly like what they said.

    Which part is vague to you?
    I found this by itself to be vague

    "A java based HTML ==> SAX parser (when a tag is recognized)"

    but with the other 2 points make it a lot clearer. Although I've never used Freemaker.

  7. #7
    SiteP0int Weazle hooknc's Avatar
    Join Date
    Dec 2004
    Location
    Socialist Republic of Boulder
    Posts
    937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, hopefully this is pretty simple.

    What happens is the parser will be listening for specific tags to occur.

    When those specific tags do occur the parser knows which tag goes with which FreeMarker template.

    There could be hundreds of tags and representative FreeMarker templates.

    In the example that you gave there would be a parser listener for the <sn:editor> tag and when that event is received the parser will know to grab a specific FreeMarker file and set values on that template.

    Then there would also be a parser listener for the <sn:editor-heading> tag and then do the same thing as above. Find a FreeMarker file that was assigned to that parser and set values on that template.

    It should work pretty well.
    baby steps... baby steps...

  8. #8
    SitePoint Wizard
    Join Date
    Apr 2007
    Posts
    1,401
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I see where your confusion is.

    I'll break it down to pieces so you'll understand better.
    1. SAX parser does not directly convert to HTML.
    2. It first uses SAX to parse the XML, while it's parsing it's initializing "data" instance. So let say particular tag is initialized then you'll initialize "data" instance accordingly. I'm sure this "data" class is probably extending some class from FreeMarker and have specific methods to assign values.
    3. After the XML has been parsed and have initialized the "data" instance then it forwards it to FreeMarker. Then, FreeMarker will generate the HTML.

    Hopefully, this makes more sense to you.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •