编辑XML与批处理文件 [英] Edit XML with batch file

查看:131
本文介绍了编辑XML与批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有任何方式创建一个可以在XML文档中编辑行的批处理文件。行将由preceding线来识别。这个想法是如下:

I am wondering if there is any way to create a batch file that can edit a line in an XML document. The line would be identified by the preceding line. the idea would be as follows:

If line == Csetting name="BaseDirectory" serializeAs="String">
    Next line = <value>User Input from begining of batch</value>

是一样的东西,即使是更多钞票还是我的梦想我的手段之外?感谢您的帮助和解答。

is something like that even posible or am I dreaming outside of my means? Thanks for the help and the answers.

推荐答案

您也许可以的批处理文件,工程的不知何故的一起砍东西。但是,这将是非常痛苦的。首先,我知道没有办法可靠地读取行到变量在批处理文件,写他们回到不变的文件。你可以逃避大部分问题的字符(如&LT; &GT; &放; | ,...),但仍然有我没能解决 1 (如无法比拟的问题带引号),这将导致这样的尝试,以可怕的失败。然后,你仍然不能够解析XML,但你宁愿到原始的文本处理这可能很容易就可能是单引号代替双引号失败。或者,一个额外的空间在什么地方抛出。或者你正在寻找的线分成几行。所有有效的XML,但痛苦的时候没有XML解析器约为解析。

You probably could hack something together in a batch file that works somehow. But it will be extraordinarily painful. First of all, I know of no way of reliably reading lines into variables in a batch file and writing them back to a file unaltered. You can escape most of the problematic characters (such as <, >, &, |, ...) but there still are problems I couldn't solve1 (such as unmatched quotation marks) that will cause such attempts to fail horribly. Then you still wouldn't be able to parse XML but you'd rather to primitive text processing which may easily fail as soon as maybe single quotes are used instead of double quotes. Or an extra space is thrown in somewhere. Or the line you're looking for is split into several lines. All valid XML but painful to parse when no XML parser is around.

该批处理文件的语言是不是真的适合此类任务。哎呀,它几乎适用于文本处理,但XML是远远超出。您可能有更多的运气(和乐趣)使用VBScript和MSXML甚至PowerShell的(如果适用)。

The batch file language isn't really suited for such tasks. Heck, it barely works for text processing but XML is way beyond. You may have more luck (and fun) with using VBScript and MSXML or even PowerShell (if applicable).

VBScript中可能是最明智的选择,在这里,你可以依靠它存在于几乎任何现代的Windows机器。

VBScript is probably the most sane choice here as you can rely on it existing on virtually any modern Windows machine.

您也可以使用XSLT和调用的命令行。有足够的XSLT处理器,在那里,可以使用并生成XSLT文件实际上是更简单(但仍需要数escapings)。

You could also use XSLT and call that from the command-line. There are enough XSLT processors out there that can be used and generating an XSLT file is actually much simpler (but will still require several escapings).


1 请注意,我可能是一个先进的批处理文件的用户/程序员,但绝不是权威的。也许这是容易做到,我只是太傻看不到了。

1 Note that I may be an advanced batch file user/programmer but by no means authoritative. Maybe it's easily possible and I'm just too stupid to see it.

这篇关于编辑XML与批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆