Java 删除xml中某些重复出现的元素
我有一个xml,希望从xml文档中删除某些元素。最初我想删除这些元素中的控制字符,或者完全删除这些元素中的数据 我的示例有效载荷如下所示。我想删除简历/内容和评论Java 删除xml中某些重复出现的元素,java,xml,Java,Xml,我有一个xml,希望从xml文档中删除某些元素。最初我想删除这些元素中的控制字符,或者完全删除这些元素中的数据 我的示例有效载荷如下所示。我想删除简历/内容和评论 <Jobs> <candidates> <address2/> <application> <comments><BR />Test emp1711 Newberg St. #4 Orego
<Jobs>
<candidates>
<address2/>
<application>
<comments><BR />Test emp1711 Newberg St. #4 Oregon, CA 97229 444-123-9752 testcandidate@gmail.com<BR />authorName: Test 1 comment content: <b>To: test test (test.test@yahoo.com)</b><br /><br />From: abc Recruitment Team (test@abc.com)<br /><br />Subject: Tester at abc<br /><br /><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="12" COLOR="#353A3F" LETTERSPACING="0" KERNING="0">Hello test,</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="12" COLOR="#353A3F" LETTERSPACING="0" KERNING="0"></FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="12" COLOR="#353A3F" LETTERSPACING="0" KERNING="0">Thank you for your interest in our abc opening. </FONT></P></comments>
<disposition>tesr Skills match</disposition>
<eId>xyz</eId>
<gender>Male</gender>
<lastUpdatedDate>1340687163</lastUpdatedDate>
<race>Undefined</race>
<resume>
<content>Test<BR />Human Resources Manager / Business Partner <BR /> portland, Oregon; 4454; <BR /> Phone 020 444456;Mobile 088768999;E-mail test@yahoo.com <BR /></content>
<format>Text</format>
</resume>
<sentDate>1789993473</sentDate>
<source>Linkedin</source>
<sourceType>Import</sourceType>
<veteranStatus>Undefined</veteranStatus>
<workflowState>Offer Accepted</workflowState>
<city>portland</city>
<companyName/>
<country>US</country>
<eId>xyz</eId>
</application>
</candidates>
<candidates>
<address2/>
<application>
<comments><BR />Test emp2711 Newberg St. #4 Oregon, CA 97229 444-123-9752 testcandidate2@gmail.com<BR />authorName: Test 2 </comments>
<disposition>Skills match</disposition>
<eId>xyz</eId>
<gender>female</gender>
<lastUpdatedDate>1340687163</lastUpdatedDate>
<race>Undefined</race>
<resume>
<content>Test<BR />Program Manager / Business Partner <BR /> portland, Oregon; 4454; <BR /> Phone 020 444456;Mobile 088768999;E-mail test@yahoo.com <BR /></content>
<format>Text</format>
</resume>
<sentDate>178444473</sentDate>
<source>Linkedin</source>
<sourceType>Import</sourceType>
<veteranStatus>Undefined</veteranStatus>
<workflowState>Offer Accepted</workflowState>
<city>portland</city>
<companyName/>
<country>US</country>
<eId>xyzabc</eId>`enter code here`
</application>
</candidates>
</Jobs>
BR/>测试emp1和x0004;加利福尼亚州俄勒冈州纽伯格街4号711号,邮编:97229 444-123-9752testcandidate@gmail.com;BR/>authorName:测试1和测试10
评论内容:b>To:test(测试)。test@yahoo.com)/b> br/>br/>发件人:abc招聘团队(test@abc.com)br/>br/>主题:abcbr的测试人员/>br/>TEXTFORMAT LEADING=“2”>P ALIGN=“LEFT”>FONT FACE=“Verdana”SIZE=“12”COLOR=“353A3F”LETTERSPACING=“0”KERNING=“0”>您好测试,/FONT>/P>/TEXTFORMAT>TEXTFORMAT LEADING=“2”>P ALIGN=“LEFT”>FONT-FACE=“Verdana”SIZE=“12”COLOR=“353A3F”LETTERSPACING=“0”KERNING=“0”>/FONT>/P>/TEXTFORMAT>TEXTFORMAT LEADING=“2”>P ALIGN=“LEFT”>FONT FACE=“Verdana”SIZE=“12”COLOR=“353A3F”LETTERSPACING=“0”KERNING=“0”>感谢您对abc开题感兴趣。/FONT>/P>
tesr技能比赛
xyz
男性
1340687163
未定义
TestBR/>人力资源经理/业务合作伙伴BR/>俄勒冈州波特兰;4454;BR/>电话020 4456;手机088768999;电子邮件test@yahoo.comBR/>
正文
1789993473
Linkedin
进口
未定义
接受报盘
波特兰
美国
xyz
BR/>测试emp2和711加利福尼亚州俄勒冈州纽伯格街4号,邮编97229 444-123-9752testcandidate2@gmail.com;;BR/>作者姓名:测试2
;
;
技术比赛
xyz
女性的
1340687163
未定义
TestBR/>项目经理/业务合作伙伴BR/>俄勒冈州波特兰;4454;BR/>电话020 444456;手机088768999;电子邮件test@yahoo.comBR/>
正文
178444473
Linkedin
进口
未定义
接受报盘
波特兰
美国
xyzabc`在此处输入代码`
使用DocumentBuilderFactory
将XML构建到文档中,并将其传递给如下函数:(nodeName
将是“注释”等)
使用DocumentBuilderFactory
将XML构建到文档中,并将其传递给如下函数:(nodeName
将是“注释”等)
你的企图是什么?你的企图是什么?
removeAllNodes(Document doc, String nodeName){
DocumentTraversal t = (DocumentTraversal) doc;
Node root = doc.getDocumentElement();
NodeIterator iterator =
t.createNodeIterator(root, NodeFilter.SHOW_ELEMENT, null, true);
for (Node n = iterator.nextNode(); n != null; n = iterator.nextNode()) {
Element e = (Element) n;
if (nodeName.equals(e.getTagName()))
root.removeChild(e);
}
}