NutzCN Logo
问答 nutz解析xml的问题
发布于 3049天前 作者 qqfe28902f 2738 次浏览 复制 上一个帖子 下一个帖子
标签:

rt。有如下一段xml,需要获取其中tag="002000d" 的值,需要如何解析:

<?xml version="1.0" encoding="UTF-8"?><dicom>
<attr tag="00020000" vr="UL" len="4">214</attr>
<attr tag="00020001" vr="OB" len="2">00\01</attr>
<attr tag="00020002" vr="UI" len="26">1.2.840.10008.5.1.4.1.1.2</attr>
<attr tag="00020003" vr="UI" len="52">1.2.276.0.7230010.3.1.4.3357366129.1124.1430536759.1</attr>
<attr tag="00020010" vr="UI" len="22">1.2.840.10008.1.2.4.51</attr>
<attr tag="00020012" vr="UI" len="28">1.2.276.0.7230010.3.0.3.5.4</attr>
<attr tag="00020013" vr="SH" len="18">GOLD_COMPRESS_V3I</attr>
<attr tag="00020016" vr="AE" len="6">GDSCP</attr>
<attr tag="00080005" vr="CS" len="10">ISO_IR 100</attr>
<attr tag="00080008" vr="CS" len="38">DERIVED\PRIMARY\LOCALIZER\CT_SOM5 TOP</attr>
<attr tag="00080016" vr="UI" len="26">1.2.840.10008.5.1.4.1.1.2</attr>
<attr tag="00080018" vr="UI" len="52">1.2.276.0.7230010.3.1.4.3357366129.1124.1430536759.1</attr>
<attr tag="00080020" vr="DA" len="8">20150502</attr>
<attr tag="00080021" vr="DA" len="8">20150502</attr>
<attr tag="00080022" vr="DA" len="8">20150502</attr>
<attr tag="00080023" vr="DA" len="8">20150502</attr>
<attr tag="0008002A" vr="DT" len="22">20150502112618.851000</attr>
<attr tag="00080030" vr="TM" len="14">112450.039000</attr>
<attr tag="00080031" vr="TM" len="14">112614.055000</attr>
<attr tag="00080032" vr="TM" len="14">112618.851000</attr>
<attr tag="00080033" vr="TM" len="14">112618.851000</attr>
<attr tag="00080050" vr="SH" len="6">183400</attr>
<attr tag="00080060" vr="CS" len="2">CT</attr>
<attr tag="00080070" vr="LO" len="8">SIEMENS</attr>
<attr tag="00080080" vr="LO" len="30">Yibing City NO.1 PPL Hospital</attr>
<attr tag="00080081" vr="ST" len="32">Street&#13;
//31703F//&#13;
District&#13;
CN</attr>
<attr tag="00080090" vr="PN" len="0"/>
<attr tag="00081010" vr="SH" len="10">CTAWP73691</attr>
<attr tag="00081030" vr="LO" len="34">Upper Extremities^1_Wrist (Adult)</attr>
<attr tag="00081032" vr="SQ" len="8">
<item off="896" len="0"/>
</attr>
<attr tag="0008103E" vr="LO" len="20">Topogram  0.6  T80f</attr>
<attr tag="00081090" vr="LO" len="24">SOMATOM Definition Flash</attr>
<attr tag="00081110" vr="SQ" len="24">
<item off="976" len="16">
<attr tag="00081150" vr="UI" len="0"/>
<attr tag="00081155" vr="UI" len="0"/>
</item>
</attr>
<attr tag="00081120" vr="SQ" len="24">
<item off="1012" len="16">
<attr tag="00081150" vr="UI" len="0"/>
<attr tag="00081155" vr="UI" len="0"/>
</item>
</attr>
<attr tag="00082111" vr="ST" len="102">Lossy compression with JPEG extended sequential 12 bit, IJG quality factor 95, compression ratio 7.452</attr>
<attr tag="00082112" vr="SQ" len="184">
<item off="1158" len="176">
<attr tag="00081150" vr="UI" len="26">1.2.840.10008.5.1.4.1.1.2</attr>
<attr tag="00081155" vr="UI" len="56">1.3.12.2.1107.5.1.4.73691.30000015050207141989400000652</attr>
<attr tag="0040A170" vr="SQ" len="66">
<item off="1276" len="58">
<attr tag="00080100" vr="SH" len="6">121320</attr>
<attr tag="00080102" vr="SH" len="4">DCM</attr>
<attr tag="00080104" vr="LO" len="24">Uncompressed predecessor</attr>
</item>
</attr>
</item>
</attr>
<attr tag="00083010" vr="UI" len="56">1.3.12.2.1107.5.1.4.73691.30000015050207301169700000049</attr>
<attr tag="00089215" vr="SQ" len="98">
<item off="1418" len="90">
<attr tag="00080100" vr="SH" len="6">121327</attr>
<attr tag="00080102" vr="SH" len="4">DCM</attr>
<attr tag="00080104" vr="LO" len="56">Full fidelity image, uncompressed or lossless compressed</attr>
</item>
</attr>
<attr tag="00090010" vr="LO" len="20">SIEMENS CT VA1 DUMMY</attr>
<attr tag="00100010" vr="PN" len="10">LI SHU LIN</attr>
<attr tag="00100020" vr="LO" len="6">183400</attr>
<attr tag="00100021" vr="LO" len="4">7026</attr>
<attr tag="00100030" vr="DA" len="8">19510502</attr>
<attr tag="00100032" vr="TM" len="14">110000.000000</attr>
<attr tag="00100040" vr="CS" len="2">M</attr>
<attr tag="00100050" vr="SQ" len="8">
<item off="1648" len="0"/>
</attr>
<attr tag="00101000" vr="LO" len="4">1009</attr>
<attr tag="00101010" vr="AS" len="4">064Y</attr>
<attr tag="00101020" vr="DS" len="4">1.7</attr>
<attr tag="00101030" vr="DS" len="2">60</attr>
<attr tag="00102154" vr="SH" len="12">02883203289</attr>
<attr tag="00180015" vr="CS" len="10">EXTREMITY</attr>
<attr tag="00180050" vr="DS" len="0"/>
<attr tag="00180060" vr="DS" len="4">120</attr>
<attr tag="00180090" vr="DS" len="4">500</attr>
<attr tag="00181000" vr="LO" len="6">73691</attr>
<attr tag="00181020" vr="LO" len="14">syngo CT 2012B</attr>
<attr tag="00181030" vr="LO" len="8">1_Wrist</attr>
<attr tag="00181100" vr="DS" len="4">512</attr>
<attr tag="00181110" vr="DS" len="6">1085.6</attr>
<attr tag="00181111" vr="DS" len="4">595</attr>
<attr tag="00181120" vr="DS" len="2">0</attr>
<attr tag="00181130" vr="DS" len="4">157</attr>
<attr tag="00181140" vr="CS" len="2">CW</attr>
<attr tag="00181150" vr="IS" len="4">2356</attr>
<attr tag="00181151" vr="IS" len="2">60</attr>
<attr tag="00181152" vr="IS" len="4">139</attr>
<attr tag="00181160" vr="SH" len="8">WEDGE_3</attr>
<attr tag="00181170" vr="IS" len="2">7</attr>
<attr tag="00181190" vr="DS" len="4">0.7</attr>
<attr tag="00181200" vr="DA" len="8">20150502</attr>
<attr tag="00181201" vr="TM" len="14">082114.000000</attr>
<attr tag="00181210" vr="SH" len="4">T80f</attr>
<attr tag="00185100" vr="CS" len="4">HFS</attr>
<attr tag="00189306" vr="FD" len="8">0.6</attr>
<attr tag="00189307" vr="FD" len="8">3.5999999999999996</attr>
<attr tag="00189309" vr="FD" len="8">100.0</attr>
<attr tag="00189311" vr="FD" len="8">0.0</attr>
<attr tag="00189323" vr="CS" len="4">NONE</attr>
<attr tag="00189324" vr="FD" len="8">0.0</attr>
<attr tag="00189345" vr="FD" len="8">0.24028170718306321</attr>
<attr tag="00189346" vr="SQ" len="68">
<item off="2148" len="60">
<attr tag="00080100" vr="SH" len="6">113691</attr>
<attr tag="00080102" vr="SH" len="4">DCM</attr>
<attr tag="00080104" vr="LO" len="26">IEC Body Dosimetry Phantom</attr>
</item>
</attr>
<attr tag="00189352" vr="FL" len="12">0.743\0.779\0.812</attr>
<attr tag="00190010" vr="LO" len="20">SIEMENS CT VA0  COAD</attr>
<attr tag="00191090" vr="DS" len="2">0</attr>
<attr tag="00191092" vr="DS" len="6">0.9179</attr>
<attr tag="00191093" vr="DS" len="6">-0.21</attr>
<attr tag="00191096" vr="IS" len="2">0</attr>
<attr tag="0020000D" vr="UI" len="44">1.2.840.1413.2015.5.2.10.1012015050.92951950</attr>
<attr tag="0020000E" vr="UI" len="56">1.3.12.2.1107.5.1.4.73691.30000015050207141989400000651</attr>
<attr tag="00200010" vr="SH" len="16">101201505029519</attr>
<attr tag="00200011" vr="IS" len="2">1</attr>
<attr tag="00200012" vr="IS" len="2">1</attr>
<attr tag="00200013" vr="IS" len="2">1</attr>
<attr tag="00200032" vr="DS" len="16">-255.5\-157\-1.5</attr>
<attr tag="00200037" vr="DS" len="26">1\-1.8369702e-016\0\0\0\-1</attr>
<attr tag="00200052" vr="UI" len="56">1.3.12.2.1107.5.1.4.73691.30000015050207301169700000047</attr>
<attr tag="00201040" vr="LO" len="0"/>
<attr tag="00201041" vr="DS" len="2">-1</attr>
<attr tag="00204000" vr="LT" len="0"/>
<attr tag="00210010" vr="LO" len="12">SIEMENS MED</attr>
<attr tag="00211011" vr="DS" len="4">0\0</attr>
<attr tag="00280002" vr="US" len="2">1</attr>
<attr tag="00280004" vr="CS" len="12">MONOCHROME2</attr>
<attr tag="00280010" vr="US" len="2">512</attr>
<attr tag="00280011" vr="US" len="2">512</attr>
<attr tag="00280030" vr="DS" len="4">1\1</attr>
<attr tag="00280100" vr="US" len="2">16</attr>
<attr tag="00280101" vr="US" len="2">12</attr>
<attr tag="00280102" vr="US" len="2">11</attr>
<attr tag="00280103" vr="US" len="2">0</attr>
<attr tag="00281050" vr="DS" len="6">50\300</attr>
<attr tag="00281051" vr="DS" len="8">350\2000</attr>
<attr tag="00281052" vr="DS" len="6">-2047</attr>
<attr tag="00281053" vr="DS" len="2">1</attr>
<attr tag="00281054" vr="LO" len="2">HU</attr>
<attr tag="00281055" vr="LO" len="16">WINDOW1\WINDOW2</attr>
<attr tag="00282110" vr="CS" len="2">01</attr>
<attr tag="00282112" vr="DS" len="6">7.452</attr>
<attr tag="00282114" vr="CS" len="12">ISO_10918_1</attr>
<attr tag="00290010" vr="LO" len="18">SIEMENS CSA HEADER</attr>
<attr tag="00290011" vr="LO" len="22">SIEMENS MEDCOM HEADER</attr>
<attr tag="00291008" vr="CS" len="6">SOM 5</attr>
<attr tag="00291009" vr="LO" len="12">VA10A 971201</attr>
<attr tag="00291010" vr="OB" len="1268">00\00\05\00\46\44\08\00\00\00\00\00\00\F6\76\40\00\00\06\00\46\</attr>
<attr tag="00291140" vr="SQ" len="5386">
<item off="4278" len="138">
<attr tag="00290010" vr="LO" len="22">SIEMENS MEDCOM HEADER</attr>
<attr tag="00291041" vr="CS" len="16">VIA_CARE_KV_WIND</attr>
<attr tag="00291042" vr="LO" len="30">ORIG WINDOW VALUES FROM CAREKV</attr>
<attr tag="00291043" vr="LO" len="12">V1 20120914</attr>
<attr tag="00291044" vr="OB" len="14">35\00\30\00\23\00\33\00\35\00\30\00\00\00</attr>
</item>
<item off="4424" len="120">
<attr tag="00290010" vr="LO" len="22">SIEMENS MEDCOM HEADER</attr>
<attr tag="00291041" vr="CS" len="10">SOM 5 TPOS</attr>
<attr tag="00291042" vr="LO" len="18">SOM 5 NULLPOSITION</attr>
<attr tag="00291043" vr="LO" len="14">VB10A 20030626</attr>
<attr tag="00291044" vr="OB" len="12">2D\30\30\30\30\31\31\30\30\30\00\00</attr>
</item>
<item off="4552" len="5104">
<attr tag="00290010" vr="LO" len="22">SIEMENS MEDCOM HEADER</attr>
<attr tag="00291041" vr="CS" len="10">SOM 7 AEC</attr>
<attr tag="00291042" vr="LO" len="18">SOM 7 ATTENUATION</attr>
<attr tag="00291043" vr="LO" len="14">VA10A 20060521</attr>
<attr tag="00291044" vr="OB" len="4996">30\30\30\30\31\39\2E\35\34\34\20\30\30\30\30\31\39\2E\36\34\33</attr>
</item>
</attr>
<attr tag="00321060" vr="LO" len="30">RequestedProcedureDescription</attr>
<attr tag="00321064" vr="SQ" len="8">
<item off="9714" len="0"/>
</attr>
<attr tag="00400275" vr="SQ" len="118">
<item off="9734" len="110">
<attr tag="00400007" vr="LO" len="34">ScheduledProcedureStepDescription</attr>
<attr tag="00400008" vr="SQ" len="8">
<item off="9796" len="0"/>
</attr>
<attr tag="00400009" vr="SH" len="16">101201505029519</attr>
<attr tag="00401001" vr="SH" len="16">101201505029519</attr>
</item>
</attr>
<attr tag="7FE00010" vr="OB" len="-1">
<item off="9864" len="4">00\00\00\00</item>
<item off="9876" len="57164">FF\D8\FF\E0\00\10\4A\46\49\46\00\01\01\00\00\01\00</item>
</attr>
</dicom>

使用下面的方法获map中取不到

  String xml=Files.read(new File("d:\\1.xml"));
            Document doc = Xmls.xml(new ByteArrayInputStream(xml.getBytes()));
			Element root = doc.getDocumentElement();
			Map<String, Object> map = Xmls.asMap(root);
			System.out.println(map);
2 回复

用dom4j

来自炫酷的 NutzCN

Document doc = DocumentHelper.parseText(“xml文本内容”);
Element root =doc.getRootElement();
list list =root.selectNodes("xpath路径");
for(Node node :list){
//在这里判断
}
或者,直接用xpath也可以

添加回复
请先登陆
回到顶部