I'm trying to come to grips with parsing an XML file but I'm having difficulty working out how to extract specific attribute data from an XMLElement. Sample XML file below:
<!DOCTYPE DEXXMLDoc SYSTEM "DEXXMLDoc.DTD">
<DEXXMLDoc name="RSM-a.xml" creator="DX8" version="8.0.6">
<designInfo studyType="ResponseSurface" designType="CCD" noOfRuns="20" noOfFactors="3" noOfResponses="2">
<designNotes>This data file created by Design-Expert 6</designNotes>
</designInfo>
<blockInfo>
<block code="0" name="Block 1"/>
<block code="1" name="Block 2"/>
</blockInfo>
<factorInfo>
<factor id="A" name="time" unit="min." type="Numeric">
<numeric low="40" high="50" stdDev="0"/>
</factor>
<factor id="B" name="temperature" unit="deg C" type="Numeric">
<numeric low="80" high="90" stdDev="0"/>
</factor>
<factor id="C" name="catalyst" unit="%" type="Numeric">
<numeric low="2" high="3" stdDev="0"/>
</factor>
</factorInfo>
As you can see, this particular XML file relies on attributes to hold much of the data. I have no trouble selecting entire XMLElement(s) by name using Cases
but I can't seem to work out how to extract specific attribute data by name. For example, I'd like to be able to extract the studyType
attribute from the designInfo
element.
This is what the XMLElement that I'm working with looks like:
XMLObject[
"Document"][{XMLObject["Doctype"]["DEXXMLDoc",
"System" -> "DEXXMLDoc.DTD"]},
XMLElement[
"DEXXMLDoc", {"name" -> "RSM-a.xml", "creator" -> "DX8",
"version" -> "8.0.6"}, {XMLElement[
"designInfo", {"studyType" -> "ResponseSurface",
"designType" -> "CCD", "noOfRuns" -> "20", "noOfFactors" -> "3",
"noOfResponses" -> "2"}, {XMLElement[
"designNotes", {}, {"This data file created by Design-Expert \
6"}]}], XMLElement[
"blockInfo", {}, {XMLElement[
"block", {"code" -> "0", "name" -> "Block 1"}, {}],
XMLElement["block", {"code" -> "1", "name" -> "Block 2"}, {}]}],
Does anyone have experience in extracting named attribute data from XMLElements?
XMLObject
by using something likeImportString[Import[xmlFileName], "XML"]
? Including that may help our users. $\endgroup$DX8 = Import["RSM-a.xml", "XML", "ReadDTD" -> False]
$\endgroup$