Open YvesR opened 6 years ago
// in: using (TextWriter writer = File.CreateText(GetCompanyRoot() + companyYml)) { yaml.Save(writer); }
// change this to: using (TextWriter writer = File.CreateText(GetCompanyRoot() + companyYml)) { yaml.Save(writer, false); // will now suppress the creation of anchors in your nodes. }
I'm sorry I was unable to answer this question in a timely fashion. As you have certainly moved on to other things, I will close this issue, but feel free to reopen it if this is still an issue.
Oh somehow I missed the previous answer. I will try it today and if it works I be happy, else I will be back here :)
Hello,
@seanfinniss answer helped that &prefix
before the number is gone, but I still have ---
removed and ...
added at the end of the yml file.
@aaubry any more advise here?
Thanks, Yves
I need to look into this. Maybe there is some information that is not being preserved.
Any progress the past year? In my case the yaml stream emits an undesirable explicit document marker as well.
Code:
var mappingNode = new YamlMappingNode();
var yaml = new YamlDocument(mappingNode);
mappingNode.Add("one", "other");
var yamlStream = new YamlStream(yaml);
var buffer = new StringBuilder();
using (var writer = new StringWriter(buffer))
{
yamlStream.Save(writer, assignAnchors: false);
output.WriteLine(writer.ToString());
}
Current output:
one: other
...
Desired output:
one: other
@cveld Try doing serialize instead. The below is F# code but it is similar to C#:
let serializer = SerializerBuilder().Build();
let SaveFile (path:string) (yaml:YamlStream) =
use file = File.Open(path, FileMode.Create)
use writer = new StreamWriter(file, System.Text.Encoding.UTF8)
serializer.Serialize(writer, yaml.Documents.[0].RootNode)
Hello, I am new to YamlDotNet, as everyone uses it, I downloaded and used it from nuget.org.
I use the component for loading, modifying and save key values from yml configuration files.
Example:
When I load, modify and save the new yml file looks like this:
So it removed the
---
from start, added...
at the end and added a &number atauth:
key.This is my code for load and modify data:
So this new resulting yml file seems still be correct, but it confuses me, is everything correct in this case?