1
votes

I have this rather complicated XML file that houses URL information. The URLs are built from several XML fields and I'm having trouble extracting these fields to assemble the URLs from them.

XML looks like this, I need to extract all the fields in (I bolded them for ease of reading) I'm at a complete loss to be able to extract all those fields. I have XMLStarlet installed and I've used it a few times in the past but this is way over my head. Any suggestions or help would be greatly appreciated.

 <DynamicUrl>
  <Name>DynamicUrl</Name>
  <CacheData>true</CacheData>
  <Path>http://contentstore.fourwindsinteractive.com/PlayerHandler.ashx</Path>
  <Query>
    <DynamicUrlNameValuePair>
      <Name>Type</Name>
      <Value xsi:type="DynamicUrlLiteral">
        <Text>download</Text>
      </Value>
    </DynamicUrlNameValuePair>
    <DynamicUrlNameValuePair>
      <Name>Title</Name>
      <Value xsi:type="DynamicUrlLiteral">
        <Text>CS00090256</Text>
      </Value>
    </DynamicUrlNameValuePair>
    <DynamicUrlNameValuePair>
      <Name>UserType</Name>
      <Value xsi:type="DynamicUrlLiteral">
        <Text>1</Text>
      </Value>
    </DynamicUrlNameValuePair>
    <DynamicUrlNameValuePair>
      <Name>LinkSource</Name>
      <Value xsi:type="DynamicUrlLiteral">
        <Text>X3/1QlyNrhGynsh+0oRn7Q==</Text>
      </Value>
    </DynamicUrlNameValuePair>
    <DynamicUrlNameValuePair>
      <Name>LinkKey</Name>
      <Value xsi:type="DynamicUrlLiteral">
        <Text>1c44ad692f10fc96922282d9bf6eb57c</Text>
      </Value>
    </DynamicUrlNameValuePair>
    <DynamicUrlNameValuePair>
      <Name>Extension</Name>
      <Value xsi:type="DynamicUrlLiteral">
        <Text>mp4</Text>
      </Value>
    </DynamicUrlNameValuePair>
    <DynamicUrlNameValuePair>
      <Name>FWIIncludeMimetype</Name>
      <Value xsi:type="DynamicUrlLiteral">
        <Text>false</Text>
      </Value>
    </DynamicUrlNameValuePair>
  </Query>
  <UseUploadData>false</UseUploadData>
  <Method>Get</Method>
  <Username />
  <Password />
  <Domain />
  <ConnectionString />
  <CommandText />
  <DeploymentBehavior>DownloadSource</DeploymentBehavior>
</DynamicUrl>
1
Hi Tom C , tomc here ;) your bold-ing isn't. maybe you should describe what you need some other waytomc
Everything that is wrapped in the <text> </text> fields.Tom C

1 Answers

1
votes
xmlstarlet sel -t -m 'DynamicUrl/Query/DynamicUrlNameValuePair/Value/Text' -v . -o '/' file.xml

Are you sure this is your question?

Maybe your problem is the xsi:type="DynamicUrlLiteral"

I just stripped them out,
maybe you have the namespace defined outside the xml fragment you supplied if you don't, you either need to define what your xsi:type is in the file or at least tell xmlstarlet on the command line with -N foo=xsi:type