|
Andrew <andrewkgentile@gmail.com> wrote in message <31f96cfe-2edb-4e72-bfe4-b82160584ea4@2g2000prl.googlegroups.com>...
> Below is a very abbreviated chunk of a much larger data file. I want
> to write some code which will search through this file and pull all
> the values shown between <Quad> and <\Quad>. There are hundreds of
> these sets of data in each file, and so I also want to assign a name
> or number to this set of data. The name of the set is slot 1, which
> is shown in the first line below. Can someone please explain how to
> pull the values out of this file? I know how to use fopen, and a few
> string functions. I have been able to find all the lines with <Quad>
> in it, but I can't figure out how to pull the values out or the string
> name. Any help would be appreciated. Thanks.
>
> <SlotData slot="001">
> <Notes></Notes>
> <Display>yes</Display>
> <ForwardExciter>
> <Range>4A</Range>
> <SpuPhaseData>0886</SpuPhaseData>
> <SpuCalData>0810</SpuCalData>
> <Quad>0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, </Quad>
Hi Andrew,
This would appear to be an XML file, so I would suggest using xmlread to read it. For example if this were a file named SlotData.xml then
dom = xmlread('SlotData.xml')
would create a dom node. Then you can use the xml dom methods to extract the information you want.
>> doc = dom.getDocumentElement
doc =
[SlotData: null]
>> slotNumber = str2num(doc.getAttribute('slot'))
slotNumber =
1
You can get a list of the Quad nodes with:
>> quadList = doc.getElementsByTagName('Quad')
quadList =
org.apache.xerces.dom.DeepNodeListImpl@1429c57
The length of the list is given by:
>> quadList.getLength
and you could process them with a loop
for index = 0:quadList.getLength-1
quadText(index+1) = quadList.item(index).getTextContent
% place processing commands here
end
Hope this helps,
Donn
|