How can I build XML in C#?

如何在C#中生成有效的XML? It depends on the scenario. XmlSerializer is certainly one way and has the advantage of mapping directly to an object model. In .NET 3.5, XDocument , etc. are also very friendly. If the size is very large, then XmlWriter is your friend. For an XDocument example: Console.WriteLine( new XElement("Foo", new XAttribute("Bar", "some & value"), n

我如何在C#中构建XML?

如何在C#中生成有效的XML? 这取决于场景。 XmlSerializer当然是一种方式,并且具有直接映射到对象模型的优点。 在.NET 3.5中, XDocument等也非常友好。 如果尺寸非常大,那么XmlWriter就是你的朋友。 对于XDocument示例: Console.WriteLine( new XElement("Foo", new XAttribute("Bar", "some & value"), new XElement("Nested", "data"))); 或者与XmlDocument相同: XmlDocument doc = new

Deciding on when to use XmlDocument vs XmlReader

I'm optimizing a custom object -> XML serialization utility, and it's all done and working and that's not the issue. It worked by loading a file into an XmlDocument object, then recursively going through all the child nodes. I figured that perhaps using XmlReader instead of having XmlDocument loading/parsing the entire thing would be faster, so I implemented that version as wel

决定何时使用XmlDocument与XmlReader

我正在优化自定义对象 - > XML序列化实用程序,这一切都已经完成并且工作,这不是问题。 它通过将文件加载到XmlDocument对象中,然后递归遍历所有子节点来工作。 我想,也许使用XmlReader而不是让XmlDocument加载/解析整个事情会更快,所以我也实现了该版本。 算法完全一样,我使用包装类来抽象处理XmlNode和XmlReader 。 例如, GetChildren方法的yield返回一个子XmlNode或一个SubTree XmlReader 。 所以我编写了一

BBCode library with Callback Tags

I am in the process of migrating my WIP website from php to C# When I was coding in php, I used a BBCode library called nbbc which allowed for "Callback Tags", which would call a function of my choice with arguments like the inner text and tag properties to get the output This functionality is very very powerful, I was able to make very advanced tags that provided functionality like

带回调标签的BBCode库

我正在将我的WIP网站从PHP迁移到C# 当我在php中进行编码时,我使用了一个名为nbbc的BBCode库,它允许使用“回调标签”,它将调用我选择的函数,使用内部文本和标签属性等参数来获取输出 这个功能非常强大,我能够制作非常先进的标签,提供像可折叠部分或数字一样的功能,使用切换按钮可以在不同测量单位之间进行转换,甚至可以从数据库中提取整个文章部分 我正在寻找的是一个.NET BBCode解析器,其中每个标记都是在该标记出

How not to encode values in XML

I have a xml document that I am editing in a C# script. I am using .load to read the doc in. .SelectSingleNode to find the node to edit. setting the .value of the attribute I want to set. Using .Save Here is the rub.... I am saving a SQL statement for the Salesforce inteface in the .value. When you use the .save it encodes (> into &gt) the string. I can't have this as Sal

如何不用XML编码值

我有一个在C#脚本中编辑的xml文档。 我正在使用.load来阅读文档。 .SelectSingleNode找到要编辑的节点。 设置我想要设置的属性的.value。 使用.Save 这里是擦.... 我正在为.value中的Salesforce接口保存一条SQL语句。 当您使用.save时,它会将字符串编码(>进入&gt)。 由于Salesforce确实知道如何编码/解码,所以我不能拥有这个功能,因此它必须是我设置的特定字符串。 没有编码的情况下保存文档的最佳方式

Work on a remote project with Eclipse via SSH

I have the following boxes: A Windows box with Eclipse CDT, A Linux box, accessible for me only via SSH. Both the compiler and the hardware required to build and run my project is only on machine B. I'd like to work "transparently" from a Windows box on that project using Eclipse CDT and be able to build, run and debug the project remotely from within the IDE. How do I set

通过SSH使用Eclipse处理远程项目

我有以下几个框: 带有Eclipse CDT的Windows盒子, 一个Linux盒子,只能通过SSH访问我。 构建和运行我的项目所需的编译器和硬件仅在机器B上运行。 我想使用Eclipse CDT从该项目的Windows框中“透明地”工作,并且能够从IDE内部远程构建,运行和调试项目。 我如何设置: 该建筑将工作? 比编写一个本地makefile更简单的解决方案,它将rsync项目,然后调用远程makefile来启动实际的构建? Eclipse托管构建有一个功能吗

Build Steps for Makefile Project in Eclipse

I am trying to use Eclipse to build some existing software (written in C), which is built with a Makefile. For this reason I created a 'Makefile project' in Eclipse. However, I just found out, the in the 'C/C++ Build / Settings' menu, I only see the 'Binary Parsers' and 'Error Parsers' tabs. However, I really need the 'Build Steps' tabs, because I also

在Eclipse中构建Makefile项目的步骤

我正尝试使用Eclipse构建一些现有的软件(用C语言编写),该软件使用Makefile构建。 出于这个原因,我在Eclipse中创建了一个'Makefile项目'。 但是,我刚刚发现,在'C / C ++ Build / Settings'菜单中,我只能看到'Binary Parsers'和'Error Parsers'选项卡。 但是,我真的需要“构建步骤”选项卡,因为我还需要添加后构建命令。 我如何让“构建步骤”选项卡出现在我的项目中? 你应该在make

Safe, or playing with fire?

Windows service: Generating a set of FileWatcher objects from a list of directories to watch in a config file, have the following requirements: File processing can be time consuming - events must be handled on their own task threads Keep handles to the event handler tasks to wait for completion in an OnStop() event. Track the hashes of uploaded files; don't reprocess if not different

安全还是玩火?

Windows服务:从配置文件中的目录列表生成一组FileWatcher对象,并具有以下要求: 文件处理可能非常耗时 - 必须在他们自己的任务线程上处理事件 保持事件处理程序任务的句柄,以等待OnStop()事件完成。 跟踪上传文件的哈希值; 如果没有不同,不要重新处理 保留文件哈希值以允许OnStart()处理服务关闭时上传的文件。 永远不要多次处理文件。 (关于#3,当没有变化时,我们确实得到事件......最主要的是因为File

Code snippet shortcut doesn't work everywhere

I have a code snippet string.Format(@"") with a shortcut sf that inserts the snippet and places the cursor in between the two double quotes. Really convenient. I can normally use it, of course, by just typing sf and hitting tab twice: However, I've just discovered that the shortcut doesn't work in all locations. For example, if I'm building this statement: if(true) thr

代码段快捷方式无处不在

我有一个代码片段string.Format(@"")带有一个快捷键sf ,它插入片段并将光标置于两个双引号之间。 真的很方便。 我通常可以使用它,当然,只需输入sf并按两次选项卡即可: 不过,我刚刚发现该快捷方式并不适用于所有位置。 例如,如果我正在构建此声明: if(true) throw new FormatException() // <-- cursor is inside these parens 当我点击sf ,快捷方式不会出现在intellisense菜单中,如果我点击Tab两次

How to use TimeZoneInfo to get local time during Daylight Savings Time?

I'm trying to use DateTimeOffset to convey a specific moment in time across any time zone. I can't figure out how to use TimeZoneInfo to deal with daylight savings time. var dt = DateTime.UtcNow; Console.WriteLine(dt.ToLocalTime()); var tz = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"); var utcOffset = new DateTimeOffset(dt, TimeSpan.Zero); Console.WriteLine(utcOffset.T

如何在夏令时期间使用TimeZoneInfo获取当地时间?

我试图使用DateTimeOffset来传达任何时区的特定时间。 我无法弄清楚如何使用TimeZoneInfo来处理夏令时。 var dt = DateTime.UtcNow; Console.WriteLine(dt.ToLocalTime()); var tz = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"); var utcOffset = new DateTimeOffset(dt, TimeSpan.Zero); Console.WriteLine(utcOffset.ToOffset(tz.BaseUtcOffset)); 打印出来: 6/2/2010 4:37:19 PM 6/2/2010 3:37:19 PM

aware DateTime when server set to UTC

My application is hosted on Windows Azure, which has all servers set to UTC. I need to know when any given DateTime is subject to daylight savings time. For simplicity, we can assume that my users are all in the UK (so using Greenwich Mean Time). The code I am using to convert my DateTime objects is public static DateTime UtcToUserTimeZone(DateTime dateTime) { dateTime = DateTime.Specif

当服务器设置为UTC时,会识别DateTime

我的应用程序托管在Windows Azure上,其中所有服务器都设置为UTC。 我需要知道任何给定的DateTime何时需要夏令时。 为了简单起见,我们可以假设我的用户都在英国(所以使用格林威治标准时间)。 我用来转换我的DateTime对象的代码是 public static DateTime UtcToUserTimeZone(DateTime dateTime) { dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc); var timeZone = TimeZoneInfo.FindSystemTimeZon