我有一个客户,他提供的文件包含混合的逗号分隔数据和 xml。逗号分隔不是问题,但 xml 对我来说是全新的。
我试图找到一个组件来做我需要的(omnixml -abandoned - using delphi built in xml component)似乎是可能的......
我有如下数据:
<Passengers>
<Passenger>
<No>1</No>
<Title>mrs</Title>
<ForeName>Anne</ForeName>
<SurName>XXXXXXXX</SurName>
<Age>33</Age>
<UWStatus>accept</UWStatus>
<Screening>
<ScreeningData>
<ScreeningPath SL="2.2" DATA="1">
<MedicalRisk>4.01</MedicalRisk>
<rootConditionId>1292</rootConditionId>
<isAMT>false</isAMT>
<regionId>4</regionId>
<isWinterSport>false</isWinterSport>
<isRetScheme>false</isRetScheme>
<isPair>false</isPair>
<LinkedCondition>3</LinkedCondition>
<LinkedConditions>
<LinkedCondition Name="High blood pressure" ICD="401.9" Type="D"/>
<LinkedCondition Name="Renal failure" ICD="586" Type="D"/>
<LinkedCondition Name="Abdominal aortic aneurysm" ICD="441.4" Type="I"/>
<LinkedCondition Name="Peripheral vascular disease" ICD="443.9" Type="I"/>
<LinkedCondition Name="Angina" ICD="414.9" Type="IS"/>
<LinkedCondition Name="Enlarged heart" ICD="425" Type="IS"/>
<LinkedCondition Name="Heart attack" ICD="414.9" Type="IS"/>
<LinkedCondition Name="Heart failure" ICD="428.0" Type="IS"/>
<LinkedCondition Name="Mini stroke" ICD="435.9" Type="IS"/>
<LinkedCondition Name="Stroke" ICD="434" Type="IS"/>
</LinkedConditions>
<ScreeningHistory>
<DeclaredCondition Score="3.56">
<conditions>
<Condition>
<id>1292</id>
<parentid>-1</parentid>
<name>Epilepsy</name>
<questions>
<Question>
<id>1</id>
<Text>If awake#$ do you normally lose consciousness during a fit/seizure?</Text>
<currentAnswer>
<Text>Yes</Text>
<id>1</id>
</currentAnswer>
</Question>
<Question>
<id>2</id>
<Text>How many fits/seizures causing loss of consciousness have you had in the last four weeks?</Text>
<currentAnswer>
<Text>0</Text>
<id>1</id>
</currentAnswer>
</Question>
<Question>
<id>3</id>
<Text>How many fits/seizures causing loss of consciousness have you had in the last six months?</Text>
<currentAnswer>
<Text>0</Text>
<id>1</id>
</currentAnswer>
</Question>
<Question>
<id>4</id>
<Text>How many unplanned hospital admissions have you had for epilepsy/seizures in the last year?</Text>
<currentAnswer>
<Text>1</Text>
<id>2</id>
</currentAnswer>
</Question>
<Question>
<id>5</id>
<Text>How many different medicines do you take for your epilepsy/seizures?</Text>
<currentAnswer>
<Text>1</Text>
<id>2</id>
</currentAnswer>
</Question>
<Question>
<id>6</id>
<Text>How long ago was your first fit/seizure?</Text>
<currentAnswer>
<Text>6 to 12 months ago</Text>
<id>2</id>
</currentAnswer>
</Question>
<Question>
<id>7</id>
<Text>If not already declared to us#$ is your epilepsy/seizures caused by:</Text>
<currentAnswer>
<Text>None of these</Text>
<id>4</id>
</currentAnswer>
</Question>
</questions>
<currentQuestionId>7</currentQuestionId>
<isAMTExclusion>false</isAMTExclusion>
<isWSExclusion>false</isWSExclusion>
<Score>3.56</Score>
<ICD>345.9</ICD>
<Deterioration>0</Deterioration>
<isOkForWS>true</isOkForWS>
<isOkForAMT>true</isOkForAMT>
<exclusionType>None</exclusionType>
</Condition>
</conditions>
</DeclaredCondition>
<DeclaredCondition Score="1.45">
<conditions>
<Condition>
<id>1332</id>
<parentid>-1</parentid>
<name>Blood pressure</name>
<questions>
<Question>
<id>1</id>
<Text>How many medicines does your doctor advise you to take for high blood pressure?</Text>
<currentAnswer>
<Text>1</Text>
<id>2</id>
</currentAnswer>
</Question>
<Question>
<id>2</id>
<Text>Has your dose been increased or have you been prescribed a new tablet in the last six months?</Text>
<currentAnswer>
<Text>No</Text>
<id>2</id>
</currentAnswer>
</Question>
<Question>
<id>3</id>
<Text>Have you been advised to take a medication to lower your cholesterol level?</Text>
<currentAnswer>
<Text>No</Text>
<id>1</id>
</currentAnswer>
</Question>
<Question MQ="2">
<id>4</id>
<Text>Have you ever been a smoker?</Text>
<currentAnswer>
<Text>Yes - gave up less than a year ago</Text>
<id>3</id>
</currentAnswer>
</Question>
</questions>
<currentQuestionId>4</currentQuestionId>
<isAMTExclusion>false</isAMTExclusion>
<isWSExclusion>false</isWSExclusion>
<Score>1.45</Score>
<ICD>401.9</ICD>
<Deterioration>1</Deterioration>
<isOkForWS>true</isOkForWS>
<isOkForAMT>true</isOkForAMT>
<exclusionType>None</exclusionType>
<LinkedConditions>
<LinkedCondition Name="High blood pressure" ICD="401.9" Type="D"/>
<LinkedCondition Name="Renal failure" ICD="586" Type="D"/>
<LinkedCondition Name="Abdominal aortic aneurysm" ICD="441.4" Type="I"/>
<LinkedCondition Name="Peripheral vascular disease" ICD="443.9" Type="I"/>
<LinkedCondition Name="Angina" ICD="414.9" Type="IS"/>
<LinkedCondition Name="Enlarged heart" ICD="425" Type="IS"/>
<LinkedCondition Name="Heart attack" ICD="414.9" Type="IS"/>
<LinkedCondition Name="Heart failure" ICD="428.0" Type="IS"/>
<LinkedCondition Name="Mini stroke" ICD="435.9" Type="IS"/>
<LinkedCondition Name="Stroke" ICD="434" Type="IS"/>
</LinkedConditions>
</Condition>
</conditions>
</DeclaredCondition>
</ScreeningHistory>
</ScreeningPath>
</ScreeningData>
</Screening>
xml 全部在一个字段中提供,没有空格(我已经格式化了这个),并且在不止一个人的地方,它显示为一个新的乘客记录。
我需要能够处理这个并提取类似的东西
乘客记录中的头衔/名字/姓氏字段 然后从分支和它相关的 和 对每个条件的每个答案重复。
我认为这很容易,但我正在努力。
我到目前为止的代码....
第一个人是正确的,第二个人失去了一个 sibling ?有错误还是我?
StartItemNode:=XMLDoc.DocumentElement.ChildNodes.First;
ANode := StartItemNode;
repeat
Title := ANode.ChildNodes['Title'].Text;
Forename := ANode.ChildNodes['ForeName'].Text;
Surname := ANode.ChildNodes['SurName'].Text;
Age:=Anode.ChildNodes['Age'].Text;
memo1.Lines.Add(Title+' '+Forename+' '+Surname+' '+Age);
CNode:=Anode.ChildNodes.FindNode('Screening');
CNode:=CNode.ChildNodes.FindNode('ScreeningData');
CNode:=CNode.ChildNodes.FindNode('ScreeningPath');
CNode:=CNode.ChildNodes.FindNode('ScreeningHistory');
CNode:=Cnode.ChildNodes.FindNode('DeclaredCondition');
CNode:=Cnode.ChildNodes.FindNode('conditions');
CNode:=Cnode.ChildNodes.FindNode('Condition');
(* Missing the 2nd illness on the 2nd node - but why *)
repeat
ill:=Cnode.ChildNodes['name'].text;
memo1.Lines.add(ill);
Unode:=Cnode;
CNode:=Cnode.NextSibling;
until cnode=nil;
如有任何帮助,我们将不胜感激。 问候 菲尔
最佳答案
我们在旧版本的 Delphi 中广泛使用了 TurboPower XML Partner。 (不记得我们是否在 Delphi 7 中使用过它)。这是 SourceForge 上最新版本的链接:http://sourceforge.net/projects/tpxmlpartner/ .您或许可以找到适合您的旧版本。
您还可以使用 msxml.dll 中的 xml com 对象。它工作得很好。以下是有关它的更多信息:https://stackoverflow.com/a/1391413/758074 .显然“位于 XMLDoc.pas 中的对象 TXMLDocument(用于 delphi 7)是 MSXML 4 或以下版本的包装器。”。但如果你导入版本 6,你应该处于良好状态。
关于xml - delphi 7 读取和处理 xml 文件的方式和组件 - 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9003003/
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
我的目标是转换表单输入,例如“100兆字节”或“1GB”,并将其转换为我可以存储在数据库中的文件大小(以千字节为单位)。目前,我有这个:defquota_convert@regex=/([0-9]+)(.*)s/@sizes=%w{kilobytemegabytegigabyte}m=self.quota.match(@regex)if@sizes.include?m[2]eval("self.quota=#{m[1]}.#{m[2]}")endend这有效,但前提是输入是倍数(“gigabytes”,而不是“gigabyte”)并且由于使用了eval看起来疯狂不安全。所以,功能正常,
Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
我试图获取一个长度在1到10之间的字符串,并输出将字符串分解为大小为1、2或3的连续子字符串的所有可能方式。例如:输入:123456将整数分割成单个字符,然后继续查找组合。该代码将返回以下所有数组。[1,2,3,4,5,6][12,3,4,5,6][1,23,4,5,6][1,2,34,5,6][1,2,3,45,6][1,2,3,4,56][12,34,5,6][12,3,45,6][12,3,4,56][1,23,45,6][1,2,34,56][1,23,4,56][12,34,56][123,4,5,6][1,234,5,6][1,2,345,6][1,2,3,456][123
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack