#149 XML Plugin: Separate/Join XML/HTML Tag Attributes

closed-fixed
Dale Anson
plugins (29)
5
2007-07-07
2007-06-22
HurricaneDavid
No

In some XML and HTML code (ColdFusion as well) tags can become very long thanks to many attributes, or just some long attributes.

This feature would split the attributes into their own line and also do the reverse (i.e. join lines that are already split).

Possible options:
* Allow user to choose whether or not to indent the separated lines, or to keep them at same indention level as the first one.
* Placement of the last ">"...
a) Allow user to choose whether the last ">" gets put on a separate line, or is at the end of the last attribute.
b) Allow user to indent last ">" flush with attributes or at same level as opening "<".

Benefits:
* Permanent Code Alteration: When you've adopted someone else's web site, who likes to keep tags in long horizontal lines, it's easy to convert that to your method, if you like them separated. Or vice-versa.
* Temporary Code Viewing: For cases when you want to keep the code one way, but view it temporarily in the other, then convert it back. For instance, to see all of an XML tag's attributes at once, perhaps make a small edit, then re-join them back into one line.
* This helps to limit horizontal scrolling, the bane of many developers.

Example of "Separate" Feature:

<table cellpadding="4" cellspacing="0" border="0" width="100%" bgcolor="#eeeeee">

would become:

<table
cellpadding="4"
cellspacing="0"
border="0"
width="100%"
bgcolor="#eeeeee"
>

Example of "Join" Feature:

<table
cellpadding="4"
cellspacing="0"
border="0"
width="100%"
bgcolor="#eeeeee"
>

would become:

<table cellpadding="4" cellspacing="0" border="0" width="100%" bgcolor="#eeeeee">

--
Thank you.

Discussion

  • HurricaneDavid
    HurricaneDavid
    2007-06-22

    • summary: Separate/Join XML/HTML Tag Attributes --> XML Plugin: Separate/Join XML/HTML Tag Attributes
     
  • Alan Ezust
    Alan Ezust
    2007-06-23

     
    Attachments
  • Alan Ezust
    Alan Ezust
    2007-06-23

    Logged In: YES
    user_id=935841
    Originator: NO

    I was trying to extract the attribute data by getting the current TreeNode's UserObject. But for some reason, I am unable to get the attribute data in XML. It appears as null. What's a good way of getting the attribute data of the current node? I'd rather reuse some of the parsing that already happened on the XML element, seeing as there is a lot of parsing code already there.

    Dale, any ideas what I am doing wrong here?

    File Added: Xml.Split-Tag.patch

     
  • Dale Anson
    Dale Anson
    2007-06-24

    Logged In: YES
    user_id=187628
    Originator: NO

    Hi Alan,

    I'm wondering if this feature wouldn't be better placed into the XmlIndenter rather than XML itself?

    Dale

     
  • Alan Ezust
    Alan Ezust
    2007-06-24

    Logged In: YES
    user_id=935841
    Originator: NO

    There is already a "split" action, I didn't add a new action yet. I just made it do something sensible when you are inside a tag. Try using the split action now. What does it do?

    Now all we need is a join, which will be trivial once I figured out how to get the parsed attributes from one of these many tree structure objects which are already in memory.

     
  • Dale Anson
    Dale Anson
    2007-06-25

    Logged In: YES
    user_id=187628
    Originator: NO

    I added a few lines to the xmlindenter, it seems to work pretty well. Right now I have the code toggling between "split" mode and "join" mode via a System property. I checked this in for others to see, revision 9839. Use the bean shell (Utilities - BeanShell - Evaluate BeanShell Expresion) to run System.setProperty("xmlindenter.splitAttributes", "true") to turn on the "split" mode, unset the property return to "join" mode. Of course, there would need to be updates to the option pane for this if everyone likes this solution. I didn't do anything about the trailing > yet.

     
  • Alan Ezust
    Alan Ezust
    2007-06-25

    Logged In: YES
    user_id=935841
    Originator: NO

    So you're applying it to every element in the document via xmlindenter? that's not exactly what was requested, although it's a nice enhancement to xmlindenter.

    I think being able to do this on an element granularity was what was originally asked for...

     
  • Dale Anson
    Dale Anson
    2007-06-26

    Logged In: YES
    user_id=187628
    Originator: NO

    Oh, okay, I didn't get that 'element granularity' part from the original. What I added to xmlindenter will split the attributes out onto multiple lines if there is more than one element for _all_ elements. I'll go ahead and add an option to xmlindenter for the toggle, but I'll leave this open. I take it you're working on a feature so that when the cursor is on an element, you will have an action that will split out the attributes for just that element?

     
  • Alan Ezust
    Alan Ezust
    2007-07-07

    Logged In: YES
    user_id=935841
    Originator: NO

    I attached a patch that goes into the treemodel and tries to get the parsed data , but I can't quite figure out the right combination of typecasts to get there. I hoped you could take a look at the attached patch (which I think should work, but doesn't) and tell me what is wrong with it.

     
  • Dale Anson
    Dale Anson
    2007-07-07

    Logged In: YES
    user_id=187628
    Originator: NO

    Alan, the only thing wrong with your patch is the extra ' at line 96 in the indent string. I removed that. The real problem was in xml.parsers.XmlTag. I got lucky and picked the right file to see the issue. It looks like the Attributes object being passed to each XmlTag is being reused and modified, so every tag ended up with the same attributes when the parse was done. I added a line in the constructor to copy the attributes, and now it seems to work well. I went ahead and checked in the changes from your patch (minus the ') and the fix for XmlTag.

     
  • Alan Ezust
    Alan Ezust
    2007-07-07

    Logged In: YES
    user_id=935841
    Originator: NO

    I think another problem with it is that it will only work for files parsed with the XML parser. This also needs to be written for the Html parser.

     
  • Dale Anson
    Dale Anson
    2007-07-07

    Logged In: YES
    user_id=187628
    Originator: NO

    Yes, it should work for html. I'll fix it.

     
  • Dale Anson
    Dale Anson
    2007-07-07

    • assigned_to: nobody --> daleanson
     
  • Dale Anson
    Dale Anson
    2007-07-07

    • status: open --> closed-fixed
     
  • Dale Anson
    Dale Anson
    2007-07-07

    Logged In: YES
    user_id=187628
    Originator: NO

    Fix splitting of attributes in html tags. Some jsp tags are fine, some are not, those that are not are those that are embedded to provide attribute values to an html tag as the parser just isn't that good.

     
  • Alan Ezust
    Alan Ezust
    2007-07-09

    Logged In: YES
    user_id=935841
    Originator: NO

    I just added a "join" action that does the reverse of split, for tags.
    I tested it, and these actions work as long as the parse happened recently enough to have the correct information about where the tag starts/ends. So in other words, repeatedly split/joining the same element won't work, eventually it will replace the data with EMPTY string.

    Also, I noticed that some of my namespace names are not in the attrib data, or are not being parsed properly.

    Also, the case of some tags ending with /> and others ending with > are is not handled.

    and finally, some attributes are delimited by ' and others by "

    So this "feature" still has some issues.

    Do we need to tell SideKick to reparse the whole document after each of those actions?

     
  • Dale Anson
    Dale Anson
    2007-07-10

    Logged In: YES
    user_id=187628
    Originator: NO

    Hi Alan, are the problems you mentioned in xml or html? I suppose this should be reopened until it's fixed?