使用R XML包删除XML中的父节点
如何使用R xml库从xml文件中删除根元素使用R XML包删除XML中的父节点,r,xml,R,Xml,如何使用R xml库从xml文件中删除根元素 <Result> <Jobs id="1"> <Job ID="000000" PositionID="0000"> <Title>Development Manager - Investment Banking - Equities Business</Title> <Summary><![CDATA[An experienced Developmen
<Result>
<Jobs id="1">
<Job ID="000000" PositionID="0000">
<Title>Development Manager - Investment Banking - Equities Business</Title>
<Summary><![CDATA[An experienced Development Manager with previous experience leading a small to mid-size team of developers in a Java/J2EE environment. A hands on role, you will be expected to manage and mentor a team of developers working on a mix of greenfield and maintenance projects.   My client, a well known investment bank, requires an experienced Development Manager to join their core technology team. This t]]></Summary>
<DateActive Date="2009-10-06T19:36:43-05:00">10/6/2009</DateActive>
<DateExpires Date="2009-11-05T20:11:34-05:00">11/5/2009</DateExpires>
<DateUpdated Date="2009-10-06 20:12:00">10/6/2009</DateUpdated>
<CompanyName>ABC Technology</CompanyName>
</Job>
</Jobs>
</Result>
发展经理-投资银行-股票业务
10/6/2009
11/5/2009
10/6/2009
ABC技术
所以,我希望输出如下
<Jobs>
<Job ID="000000" PositionID="0000">
<Title>Development Manager - Investment Banking - Equities Business</Title>
<Summary><![CDATA[An experienced Development Manager with previous experience leading a small to mid-size team of developers in a Java/J2EE environment. A hands on role, you will be expected to manage and mentor a team of developers working on a mix of greenfield and maintenance projects.   My client, a well known investment bank, requires an experienced Development Manager to join their core technology team. This t]]></Summary>
<DateActive Date="2009-10-06T19:36:43-05:00">10/6/2009</DateActive>
<DateExpires Date="2009-11-05T20:11:34-05:00">11/5/2009</DateExpires>
<DateUpdated Date="2009-10-06 20:12:00">10/6/2009</DateUpdated>
<CompanyName>ABC Technology</CompanyName>
</Job>
</Jobs>
发展经理-投资银行-股票业务
10/6/2009
11/5/2009
10/6/2009
ABC技术
所以,没有了
<Result></Result>
只需通过XPath选择所需的节点,然后使用
saveXML
保存到文件。下面显示等效呼叫:
newdoc <- xpathApply(doc, "/Result/Jobs") # OR getNodeSet(doc, "/Result/Jobs")
newdoc
# [[1]]
# <Jobs id="1">
# <Job ID="000000" PositionID="0000">
# <Title>Development Manager - Investment Banking - Equities Business</Title>
# <Summary><![CDATA[An experienced Development Manager with previous experience leading a small to mid-size team of developers in a Java/J2EE environment. A hands on role, you will be expected to manage and mentor a team of developers working on a mix of greenfield and maintenance projects.   My client, a well known investment bank, requires an experienced Development Manager to join their core technology team. This t]]> </Summary>
# <DateActive Date="2009-10-06T19:36:43-05:00">10/6/2009</DateActive>
# <DateExpires Date="2009-11-05T20:11:34-05:00">11/5/2009</DateExpires>
# <DateUpdated Date="2009-10-06 20:12:00">10/6/2009</DateUpdated>
# <CompanyName>ABC Technology</CompanyName>
# </Job>
# </Jobs>
# attr(,"class")
# [1] "XMLNodeSet"
saveXML(newdoc[[1]], file="Output.xml")
我试着用removeNodes做这件事,但2小时后就没能成功了。你的解决方案很简单。
removeAttributes(newdoc[[1]])