Re: Spot editing a YAML document

Oren Ben-Kiki <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <1207760162.5445.107.camel@nero>
The spec itself is neutral on this, it just defines what is or isn't
valid YAML. In principle, if you dump(load(YAML)), all the presentation
details may be lost (it could come out as JSON! :-). That said,
preserving such details is useful as you point out. This however
requires a different sort of interface... For example, a streaming
transformer API (newValue = callback(oldValue) or some such). I don't
think there are such implementations though.

Of course you could "cheat". In your example, *if* your YAML is
*guaranteed* to be formatted in a specific way, a simple
Perl/Ruby/Python - even sed - script could do the trick...

On Tue, 2008-04-08 at 00:04 -0400, Trans wrote:
> Has anyone given any thought to how best to "spot edit" a YAML
> document? What I mean by that is, lets say we have a document:
> 
>   ---
>   project: foo
>   version: 0.0.1
>   status: beta
>   description:
>     Just a Foo program.
>     Does nothing whatsoever.
> 
> Now say I want to bump the version field via a script. Normally I
> would have to load the whole document, change the field, then re-emit
> it back to the file. What happens during this round-trip, of course,
> is we loose the layout and get something like:
> 
>   ---
>   status: beta
>   project: foo
>   description: This is just a foo program. It does nothing whatsoever.
>   version: 0.0.1
> 
> But I need to be able to change version, or whatever field, without
> disrupting the entire layout of the file. The reason is the files I
> use are often hand edited and I want to respect the users layout
> preferences.
> 
> Does the YAML specification in some way make this feasible?
> 
> Thanks,
> T.
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
> Register now and save $200. Hurry, offer ends at 11:59 p.m., 
> Monday, April 7! Use priority code J8TLD2. 
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> _______________________________________________
> Yaml-core mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/yaml-core


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.