作者sicao (adios)
看板RegExp
标题XML取值问题
时间Tue Sep 6 20:27:37 2022
想问一下 手边有个xml
架构大概是这样..
想请问一下 该怎麽下才能取得<TOTA>里length的值??
<TITA>
<TT>(其他外层的tag)
<TxField id="AVG03" cname="hh" datatype="9" lengthtype="F" padchar=" "
justify="" default="" length="13" lengthExpr="" scale="2" tagSize="0"
lengthSize="0" encoding="" shiftInOut="Y" invisibleChar="TrimAndPadRight"
memo="" optional="N" overwrite="N" codec="" renderTag="" charFormat="" />
<TxField id="AVG03" cname="hh" datatype="9" lengthtype="F" padchar=" "
justify="" default="" length="13" lengthExpr="" scale="2" tagSize="0"
lengthSize="0" encoding="" shiftInOut="Y" invisibleChar="TrimAndPadRight"
memo="" optional="N" overwrite="N" codec="" renderTag="" charFormat="" />
.....
</TT>
</TITA>
<TOTA>
<TT>(其他外层的tag)
<TxField id="AVG03" cname="hh" datatype="9" lengthtype="F" padchar=" "
justify="" default="" length="13" lengthExpr="" scale="2" tagSize="0"
lengthSize="0" encoding="" shiftInOut="Y" invisibleChar="TrimAndPadRight"
memo="" optional="N" overwrite="N" codec="" renderTag="" charFormat="" />
<TxField id="AVG03" cname="hh" datatype="9" lengthtype="F" padchar=" "
justify="" default="" length="13" lengthExpr="" scale="2" tagSize="0"
lengthSize="0" encoding="" shiftInOut="Y" invisibleChar="TrimAndPadRight"
memo="" optional="N" overwrite="N" codec="" renderTag="" charFormat="" />
.....
</TT>
</TOTA>
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 223.137.17.234 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/RegExp/M.1662467259.A.D60.html
1F:→ microloft: /(?<=<TOTA>[^]+\blength=")[^"]+(?="[^]+<\/TOTA>)/g 09/06 20:54
2F:→ microloft: 上面适用於你目前的内容,但若有多组<TOTA>会有问题 09/06 20:57
3F:→ microloft: 这种还是直接用XML相关解析工具会比较稳健 09/06 21:00
4F:→ sicao: 谢谢!不过在regex101测试好像不行? 09/07 08:03
5F:→ microloft: 我用ECMAScript语法,regex101的话要在左侧栏自己切换 09/07 19:17