Sort by

recency

|

8 Discussions

|

  • + 0 comments

    Here is Querying XML Datastores with XPath - 1 problem solution - https://www.gyangav.com/2022/11/hackerrank-querying-xml-datastores-with-xpath-1-problem-solution.html

  • + 0 comments
    # Standard ruby library for XML parsing
    require 'rexml/document'
    include REXML
    
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    xmlText = "movies.xml" 
    
    # Read the input XML Fragment
    while line = gets()
    	xmlText += line
    end
    
    doc = Document.new xmlText
    
    # XPath Selector for listing the titles of the movies, in the same order as which they occur in the given XML.
    # Fill in the blanks to complete the required XPath selector query
    puts doc.elements.each("collection/movie/@title")
    
  • + 0 comments

    puts doc.elements.each("collection/movie/@title")

  • + 0 comments

    //collection/movie/data(@title)

  • + 0 comments

    Answer:

    require 'rexml/document' include REXML xmlText = "movies.xml"

    while line = gets() xmlText += line end

    doc = Document.new xmlText puts doc.elements.each("collection/movie/@title")