自动编辑xml文件中的数字数据 [英] Automating edit for numeric data in an xml file

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

问题描述

首先在这里发帖,所以大家好。



我希望你能提供帮助。我想自动编辑包含纬度和经度数据的XML文件。原始文件有一个WorldPosition语句,其中包含纬度和经度(和海拔高度),如下所示:



First post here so a big Hi to all.

I hope you can help. I would like to automate the editing of an XML file containing latitude and longitude data. The original file has a "WorldPosition" statement containing Latitude and Longitude (and Altitude) as follows:

<WorldPosition>N43 11 21.126487,E0 8 8.312166,0.00</WorldPosition>





我非常想将其编辑为:





I would very much like to edit this to:

<WorldPosition>N43* 11' 21.126487",E0* 8' 8.312166",0.00</WorldPosition>





其中学位用*注明,分钟用''以及。



简单但是l因为在每个XML文件中可能有数百种这种类型的WorldPosition字段,所以手工操作非常流行。有没有办法使用不太昂贵的XML类型编辑器自动执行此编辑?任何例子和解释都会感激不尽。



编辑21Dec12:



为了自动编辑,我首先需要隔离''WorldPosition''定义中的文本字符串(不是正确的术语 - 也许你可以纠正我吗?)

纬度(N或S)和经度( E或W)数字格式类似,具有度数(整数0到355),分钟(整数0到59)和秒(整数0到59)。因此,一个简单的查找和替换例程是合适的(即找到第一个''''(这里我的意思是''空格'')并替换为''*''(''space''后跟''asterisk' '),等等。

我的问题是我没有专业知识来执行这些步骤。虽然我理解机制,但我没有知识 - 或工具 - 实现解决方案。

如果有可能引导我对这个或类似的问题,我会非常感激。不知道从哪里开始也许是最克服问题的令人沮丧的阶段 - 我相信你明白了!



再次感谢 - David W.



where the degrees are annotated with *, minutes with '' and seconds with ".

Simple but laborious to do by hand as there may be hundreds of this type of WorldPosition field in each XML file. Is there a way to automate this edit using a not too expensive XML type editor? Any examples and explanation would be gratefully received.

Edit 21Dec12:

In order to automate this editing, I need first to isolate the text string within the ''WorldPosition'' definitions (not the correct term - maybe you can correct me, please?)
The latitude (N or S) and Longitude (E or W) numeric formats are similar, with Degrees (integer 0 to 355), Minutes (integer 0 to 59) and Seconds (integer 0 to 59). So a simple find-and-replace routine would be appropriate (i.e find first '' '' (here I mean ''space'') and replace with '' *'' (''space'' followed by ''asterisk''), and so on.
My problem is that I do not have the expertise to do either of these steps. Whilst I understand the mechanism, I have not the knowledge - or tool(s) - to implement the solution.
If it is at all possible to direct me to a turorial on this, or similar, I''d be very grateful. Not knowing where to start is, perhaps, the most frustrating stage in overcoming a problem - I''m sure you understand!

Many Thanks Again - David W.

推荐答案

如果没有禁忌症,我会将整个文件威胁为纯文本并仅使用正则表达式对其进行转换。

这是一个可用于搜索的表达式:< WorldPosition>(([NS] \d +)(\d +)(\d +(\。 \\ d +)?)),(([EW] \d +)(\d +)(\d +(\.\\\ +)?)),(0.00)< / WorldPosition> ,以及替换:< WorldPosition> \2 * \'''\'4,\ 7 * \8''\ 9',\ 11< ; / WorldPosition>
If there is no contraindication, I would threat the whole file as plain text and use only regular expression to transform it.
Here is an expression you could use to search: <WorldPosition>(([NS]\d+) (\d+) (\d+(\.\d+)?)),(([EW]\d+) (\d+) (\d+(\.\d+)?)),(0.00)</WorldPosition>, and this on as replacement: <WorldPosition>\2* \3'' \4",\7* \8'' \9",\11</WorldPosition>


您可以使用DOM搜索节点,然后编写正则表达式或一些字符串混搭代码以插入所需的值。你不确定哪一点?



通过XMLDocument和XDocument解析XML文档 [ ^ ]
You can use the DOM to search your nodes, then write a regex or some string mashing code to insert the values you want. Which bit are you not sure of ?

Parse XML Documents by XMLDocument and XDocument[^]


这篇关于自动编辑xml文件中的数字数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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