Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
reformatting some set attributes (Read 6918 times)
Rafter T. Sass
Full Member
*
Offline



Posts: 100
Burlington, VT
reformatting some set attributes
Apr 3rd, 2008, 8:31pm
 
It's me again.

So, I'm no longer adding superfluous quotes to my set values, thanks to the kind clarifications of Amber and the Marks.

But I've still got the superfluous quotes, making my queries and set attribute fields all... mucky.

Is there a way, elegant or no, by which I can replace the quoted values for non-quoted, without schlepping together a value-for-value agent or team of agents?

I seem to remember someone posting a suggestion about this, but either it mysteriously disappeared, or I dreamed it. (Odds are running about 60/40 in favor of having dreamed it...)

Thanks!
Back to top
 
« Last Edit: Apr 03rd, 2008, 8:32pm by Rafter T. Sass »  
raughter   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: reformatting some set attributes
Reply #1 - Apr 4th, 2008, 9:57am
 
There's an easy way but tacky way, and a harder (in this case) but more elegant way.

Easy way: make a copy of the tinderbox file. Open the copy in a text editor.  Search for the set value; you'll find some examples in quotes:

     <attribute name="tags" >&quot;frogs&quot;;dogs</attribute>

Delete the &quot; elements.  So, global replace of &quot;frogs&quot; with frogs wil do the trick.

A nicer solution would be to make an agent that collects notes with the old tag, remove that tag, and add a new tag.  The query would be

    Query: tags("frogs")

where tags is your set attribute.

The action would be

    Action: tags = $tags -  TheBadTag + TheGoodTag

The tricky bit here is that quotation marks are meaningful in actions, so we need to find a way to say "yes, I mean that the crazy tag does have a quotation mark!"  The easiest way to do this is to make a user attribute TheBadTag, and in the agent give that attribute the value of "frogs" including the quotation mark.  So, the action would be

    Action: tags=$tags - $TheBadTag(agent) + "frogs"


Back to top
 
« Last Edit: Apr 4th, 2008, 12:30pm by Mark Bernstein »  
WWW   IP Logged
DerikBadman
Ex Member




Re: reformatting some set attributes
Reply #2 - Apr 4th, 2008, 12:06pm
 
Couldn't you do something with a regex to replace them all at once?

Searching for a \"(.+?)\" and replacing with $1

Not that I've tried it out...
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: reformatting some set attributes
Reply #3 - Apr 4th, 2008, 12:29pm
 
DerikBadman: You'd want to search for &quot;(.+)&quot; or something like that (and do you need to escape the ampersand?)  .  This would save some time.  But you only need to do this once, and it's reassuring to see the changes as they're made.
Back to top
 
« Last Edit: Apr 4th, 2008, 12:29pm by Mark Bernstein »  
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: reformatting some set attributes
Reply #4 - Apr 4th, 2008, 1:15pm
 
Yes, in a text editor that supports regular expressions find/replace like BBEdit (or its free little brother TextWrangler) you can look for the attribute, but it's not the thing to try unless you understand a little about regexs. Lets assume the bad data is in a set-type user attribute "MySet". First, we back up the file! Now open the TBX file in your text editor so you can see the source XML. We need to find all lines like:

<attribute name="MySet" >Good;&quot;Bad&quot;;Bad;Nice;&quot;Poor&quot;;OK</attribute>

Note how the unwanted " quotes around the 'bad' values are saved in the source as &quot. Your replacement regex can't just remove the &quot unless you know the quoted vaues aren't also present as unquoted values. TB normally removes dupes when setting values so creating them in source by turning Good;&quot;Bad&quot;;Bad; into Good;Bad;Bad; might upset things. You need to allow for quotes in any position and for there being no semi-colon after the last value, etc.... I'll leave it to someone with more regex experience to suggest the actual regex!

If there aren't 000s of entries and you don't fancy tackling a replacement regex but don't mind manually editing each entry, do a regex find for:

<attribute name="MySet" >.*(&quot;)+.*</attribute>

that will find MySet entries but only those with quotes in the values. In BBEdit/TextWrangler you can do a 'Find All' and use that report window to work through all the bad entries correcting them. Run the find again when done to check you missed nothing. Unless it's very few entries, I'd go the agent route Mark B's suggested. But the question was asked...
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: reformatting some set attributes
Reply #5 - Apr 4th, 2008, 1:29pm
 
Tip:  these techniques are also very useful for merging tags and topics that turn out, over time, to mean the same thing.

For example, my weblog has categories for "food" and for "cooking".  At one point, I suppose I had a reason for the two categories, but now I can't remember what it is.  But I do need to remember to apply both tags to dinner!  The tricks in this discussion apply just as well to replacing two tags with one.
Back to top
 
 
WWW   IP Logged
Pages: 1
Send Topic Print