Thread Subject: strings and files and concatenations

Subject: strings and files and concatenations

From: Andrew

Date: 13 Aug, 2009 02:30:29

Message: 1 of 2

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>

Subject: strings and files and concatenations

From: Donn Shull

Date: 13 Aug, 2009 03:19:05

Message: 2 of 2

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

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
concatenate 2 s... Sprinceana 13 Aug, 2009 01:48:58
concatenate 2 f... Sprinceana 13 Aug, 2009 01:48:58
rssFeed for this Thread

Contact us at files@mathworks.com