Hi Everyone,
I’m required to write a ruby script that can edit an xml file, this
script must uncomment a block of the xml document.
jetty.xml
<!-- =========================================================== -->
<!-- Server Thread Pool -->
<!-- =========================================================== -->
<Set name="ThreadPool">
<!-- Default queued blocking threadpool -->
<New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
<Set name="minThreads">10</Set>
<Set name="maxThreads">10000</Set>
<Set name="detailedDump">false</Set>
</New>
</Set>
<!-- =========================================================== -->
<!-- Set connectors -->
<!-- =========================================================== -->
<!--
<Call name="addConnector">
<Arg>
<New
class=“org.eclipse.jetty.server.nio.SelectChannelConnector”>
50000
2
false
8443
5000
5000
–>
50000
1500
false
</Configure>
How can i remove comments for this block only?
on my ruby script i have the following code, when i run the code it
removes
all the comments and its content as well.
require ‘nokogiri’
file = File.read(“jetty.xml”)
xml = Nokogiri::XML(file)
#replace with a space
xml.xpath("//comment()").each do |node|
node.content =node.content.gsub!(/(^\D\W[<!–}]\W[–>])/,’ ')
end
File.open(“newjetty.xml”,“w”) do |f|
f.write xml.to_xml
end