How do I get an XML tag attribute value with namespace?

RobertD

New Member
I'm parsing a pptx file and ran into an issue. This is a sample of the source XML:\[code\]<?xml version="1.0" encoding="UTF-8" standalone="yes"?><p:presentation xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"> <p:sldMasterIdLst> <p:sldMasterId id="2147483648" r:id="rId2"/> </p:sldMasterIdLst> <p:sldIdLst> <p:sldId id="256" r:id="rId3"/> </p:sldIdLst> <p:sldSz cx="10080625" cy="7559675"/> <p:notesSz cx="7772400" cy="10058400"/></p:presentation>\[/code\]I need to to get the \[code\]r:id\[/code\] attribute value in the \[code\]sldMasterId\[/code\] tag.\[code\]doc = Nokogiri::XML(path_to_pptx)doc.xpath('p:presentation/p:sldMasterIdLst/p:sldMasterId').attr('id').value\[/code\]returns \[code\]2147483648\[/code\] but I need \[code\]rId2\[/code\], which is the \[code\]r:id\[/code\] attribute value.I found the \[code\]attribute_with_ns(name, namespace)\[/code\] method, but\[code\]doc.xpath('p:presentation/p:sldMasterIdLst/p:sldMasterId').attribute_with_ns('id', 'r')\[/code\]returns nil.
 
Back
Top