Need Help ?

Home / Expert Answers / Other / exercise-2-given-the-xml-file-log-xml-write-a-program-using-xpath-to-extract-the-information-and-out

(Answered): Exercise 2 Given the xml file (log.xml), write a program using xpath to extract the information and ...



Exercise 2 Given the xml file (log.xml), write a program using xpath to extract the information and output the result in theOutput Result: date=2007-12-01 time=10:00:00 message=Warning1 date=2007-12-01 time=14:00:00 message=Error1 date=2007-12-02 tiIn [ ]: import xml.etree. ElementTree as et #TODO for Exercise 1 def extract_information(): # YOUR CODE HERE raise NotImpleme

Exercise 2 Given the xml file (log.xml), write a program using xpath to extract the information and output the result in the given format. log.xml <logList> <list code="w001" message="Warning1"/> <list code="w002" message="Warning2"/> <list code="e001" message="Errorl"/> <list code="e002" message="Error2"/> <day date="2007-12-01"> <log time="10:00:00" code="w001"/> <log time="14:00:00" code="e001"/> </day> <day date="2007-12-02"> <log time="13:00:00" code="2002"/> <log time="15:00:00" code="e001"/> </day> </logList> Output Result: date=2007-12-01 time=10:00:00 message=Warning1 date=2007-12-01 time=14:00:00 message=Error1 date=2007-12-02 time=13:00:00 message=Error2 date=2007-12-02 time=15:00:00 message=Error1 Hint: • To get the element with attribute value equals to a variable, use string formatting to insert the field value into the XPath expression, e.g., xroot.find('.//log[@time=" {0}"]'.format(time)). To get the parent element of current element, use xroot.find('.//log[ @code="w001"]/..' (finds the parent element of log element with attribtue code equals to w001). In [ ]: import xml.etree. ElementTree as et #TODO for Exercise 1 def extract_information(): # YOUR CODE HERE raise NotImplementedError() return messages In [ ]: #You can write your own tests here In [ ]:


We have an Answer from Expert

View Expert Answer

Expert Answer


Answer to Exercise 2 Given the xml file (log.xml), write a program using xpath to extract the information and output the result in...
We have an Answer from Expert

Buy This Answer $4

Place Order