使用XML starlet来提取值

时间:2017-04-04 19:42:06

标签: xml xpath xmlstarlet

鉴于:

 <UOIS UOI_ID="9352923211a63c6fe6643832d3c4a7786e21ed26" CONTENT_TYPE="VIDEO" NAME="TR2014_295_11_1a_PM.mov" VERSION="1" METADATA_STATE_DT="2016-06-03 17:01:10.0" METADATA_STATE_USER_ID="1" IMPORT_DT="2016-06-03 13:35:58.0" IMPORT_USER_ID="1" MASTER_OBJ_MIME_TYPE="video/quicktime" MODEL_ID="30001">
 <FILE_SIZE_VIEW CONTENT_SIZE="100948.92       " />
 <SI_AV_ASSET_METADATA VIDEO_BIT_RATE="226 Mbps" REGIONAL_ENCODING_FORMAT="NTSC" DC_TITLE="TR2014_295_11_1a_PM.mov" VIDEO_ORIGINATION_FORMAT="Betacam SP" AV_ASSET_TYPE="Video - Original" MODIFICATION="Editing Allowed" />
 <SI_AUDIO_LANGUAGE_DTLS LANGUAGE="English" />
 <SI_ASSET_METADATA HOT_FOLDER_IMPORT_ID="23335" PUBLIC_USE="No" PRIMARY_CREATOR="Bl" CAPTURE_DEVICE="Captured via Sony DVW-A500 Digital Betacam VTR, SDI to Blackmagic UltraStudio Express ADC to Blackmagic Media Express software" IS_RESTRICTED="No" OWNING_UNIT_UNIQUE_NAME="NMAAHC-TR2014_295_11_1a_PM" ALTERNATE_IDENTIFIER_1="TR2014.295" COLOR_SPACE="YCbCr " EMBARGO="No" />
 </UOIS>

如何提取UOI_IDOWNING_UNIT_UNIQUE_NAME的值? 如何从不同的标签中提取属性并将它们连接起来是基本问题。

1 个答案:

答案 0 :(得分:0)

假设SI_ASSET_METADATAUOIS的直接孩子(目前,由于UOIS元素尚未关闭,因此不清楚):

xmlstarlet sel -t -m "//UOIS" \
        -v "concat(@UOI_ID, ', ' , SI_ASSET_METADATA/@OWNING_UNIT_UNIQUE_NAME)" \
        -n your_xml.xml