如果获取到节点话,就调用attributeValue(String name)方法获取里面的值就好了。
$cat testsh
#!/bin/bash
if [ -z $1 ];then
echo 'USAGE:COMMAND FILENAME'
exit 0
fi
filename=recordtxt
HOST=(`sed -n 's/>\(\)<\/host>/\1/p' $1`)
OIDG=(`sed -n 's/>\(\)<\/oidgroupname>/\1/p' $1`)
COMM=(`sed -n 's/>\(\)<\/communitystring>/\1/p' $1`)
DESC=(`sed -n 's/>\(\)<\/description>/\1/p' $1`)
FILE=(`ls -l $filename >/dev/null 2>&1 | awk '{print $8}'`)
if [ ! -z $FILE ];then
echo -e "host\t\toidgroupname\t\tcomm\t\tdesc" >$filename
fi
for((i=0;i<${#HOST[@]};i++));do
echo -e "${HOST[i]}\t${OIDG[i]}\t${COMM[i]}\t\t${DESC[i]}" >>$filename
done
$/testsh file
$cat recordtxt
host oidgroupname comm desc
19216811 CpuUtilization_MF public 19216811_CPUUtilizaton
19216812 CpuUtilization_MF public 19216812_CPUUtilizaton
19216813 CpuUtilization_MF public 19216813_CPUUtilizaton
19216814 CpuUtilization_MF public 19216814_CPUUtilizaton
19216815 CpuUtilization_MF public 19216815_CPUUtilizaton
php是可以读取读取xml文件的。同时也可以遍历节点。网上有很多方法。你可以百度下。这里给你贴代码的话有很多代码。
举例: 有个名字为axml的文件 。内容为:
<xml version=”10″ encoding=”gb2312″>
<xml>
<list>111</list>
<list>2222</list>
<list>3333</list>
</xml>
读取:
<php
$xml = new DOMDocument();
$xml->load('axml');
foreach($xml->getElementsByTagName('list') as $list)
{
$value = $list->firstChild->nodeValue;
echo $value”<br />”;
}
>
输出为:111
222
333
用jdomjar
import javaioFile;
import orgjdomDocument;
import orgjdomElement;
import orgjdominputSAXBuilder;
public class Test {
public static void main(String[] args)throws Exception {
File file = new File("c:/xmlcountxml");
SAXBuilder builder = new SAXBuilder();
Document doc = builderbuild(file);
Element root =docgetRootElement();
Systemoutprintln("month-count:"+rootgetAttributeValue("month-count"));
Systemoutprintln("total-count:"+rootgetAttributeValue("total-count"));
Systemoutprintln("temp-count:"+rootgetAttributeValue("temp-count"));
Systemoutprintln("week-count:"+rootgetAttributeValue("week-count"));
Systemoutprintln("day-count:"+rootgetAttributeValue("day-count"));
Systemoutprintln("year-count:"+rootgetAttributeValue("year-count"));
}
}
用XPath比较简单点也可以用xmldom
xmltype('<xml version="10" encoding="gbk">
<SERVICE>
<IDA_SVR_USERBILL>
<CALL_METHOD>queryProcessStepList</CALL_METHOD>
</IDA_SVR_USERBILL>
</SERVICE>')extract('//CALL_METHOD/child::text()')getstringval()
测试:
SELECT xmltype('<xml version="10" encoding="gbk">
<SERVICE>
<IDA_SVR_USERBILL>
<CALL_METHOD>queryProcessStepList</CALL_METHOD>
</IDA_SVR_USERBILL>
</SERVICE>')extract('//CALL_METHOD/child::text()')getstringval()
from dual;
以上就是关于Linux 中如何解析获取文件中XML标签对中的值全部的内容,包括:Linux 中如何解析获取文件中XML标签对中的值、php 获取xml某个节点的所有内容、如何用java获得xml文件中标签的属性列表值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)