score:0

Accepted answer

Filtering for script isn't really necessary since \\ will traverse the entire structure and return those elements that match.

xml \\ "script"

res1: scala.xml.NodeSeq = NodeSeq(<script id="ssl-cert" output="placeholder text">
...

Print the script tags in res1

res1.foreach(println(_)) 

<script id="ssl-cert" output="placeholder text">
<table key="subject">
...

Update regarding comments

To get only the port nodes that contain script nodes

(xml \\ "ports" \\ "port").filter(n => n.descendant.exists(_.label == "script"))

Outputs:

res81: scala.xml.NodeSeq =
NodeSeq(<port protocol="tcp" portid="443">
                <state state="open" reason="syn-ack" reason_ttl="0"/>
                <service name="https" method="table" conf="3"/>
                <script>
                    <table key="subject">
                        ...

descendant gives a List[Node] which is one way to do it. There are others but that worked for me.


Related Query

More Query from same tag