求助用c语言 解析字符 应该怎么样去解析

以其而始 2017-06-16 11:14:42
现在有一个文件,我需要得到 <featurename> 下一级的标签 EntityStateEntry 应该怎么得到?
并且文件中可能有多个 <featurename> 都需要得到下一级的 标签 用c语言应该怎么写?
求个解析的代码, 不想用xml解析
htmlID=1001&MessageID=196&<rpc message-id="196" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<get><filter type="subtree">
<featurename istop="true" type="mib">
<EntityStateEntry position="iso.org.dod.internet.private.enterprises.Mgmt.Datacomm.EntityExtentMIB.EntityExtObjects.EntityState.EntityStateTable">
<EntityCpuUsage/>
<EntityMemUsage/>
<EntityTemperature/>
<EntityCpuUsageThreshold/>
<EntityMemUsageThreshold/>
<EntityTemperatureThreshold/>
</EntityStateEntry>
</featurename>
</filter>
</get>
</rpc>]]>]]>er>
</get>
</rpc>]]>]]>

也可能有多个
htmlID=1001&MessageID=196&<rpc message-id="196" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<get><filter type="subtree"><featurename istop="true" type="mib"><entPhysicalEntry position="iso.org.dod.internet.mgmt.mib-2.entityMIB.entityMIBObjects.entityPhysical.entPhysicalTable"><entPhysicalSerialNum/><entPhysicalDescr/></entPhysicalEntry></featurename></filter></get></rpc>]]>]]>
htmlID=1001&MessageID=196&<rpc message-id="196" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<get><filter type="subtree">
<featurename istop="true" type="mib">
<EntityStateEntry position="iso.org.dod.internet.private.enterprises.Mgmt.Datacomm.EntityExtentMIB.EntityExtObjects.EntityState.EntityStateTable">
<EntityCpuUsage/>
<EntityMemUsage/>
<EntityTemperature/>
<EntityCpuUsageThreshold/>
<EntityMemUsageThreshold/>
<EntityTemperatureThreshold/>
</EntityStateEntry>
</featurename>
</filter>
</get>
</rpc>]]>]]>

在此谢谢了
...全文
85 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
自信男孩 2017-06-16
  • 打赏
  • 举报
回复
引用 2 楼 m0_37820090 的回复:
恩 但是有些原因不能用 xml 解析的方法去解析,需要解析直接得到
按照字符串解析函数一行行的分析,会比较麻烦;
以其而始 2017-06-16
  • 打赏
  • 举报
回复
恩 但是有些原因不能用 xml 解析的方法去解析,需要解析直接得到
真相重于对错 2017-06-16
  • 打赏
  • 举报
回复
用msxml组件
赵4老师 2017-06-16
  • 打赏
  • 举报
回复
__min Returns the smaller of two values. type __min( type a, type b ); Routine Required Header Compatibility __min <stdlib.h> Win 95, Win NT For additional compatibility information, see Compatibility in the Introduction. Libraries LIBC.LIB Single thread static library, retail version LIBCMT.LIB Multithread static library, retail version MSVCRT.LIB Import library for MSVCRT.DLL, retail version Return Value The smaller of the two arguments Parameters type Any numeric data type a, b Values of any numeric type to be compared Remarks The __min macro compares two values and returns the value of the smaller one. The arguments can be of any numeric data type, signed or unsigned. Both arguments and the return value must be of the same data type. Example /* MINMAX.C */ #include <stdlib.h> #include <stdio.h> void main( void ) { int a = 10; int b = 21; printf( "The larger of %d and %d is %d\n", a, b, __max( a, b ) ); printf( "The smaller of %d and %d is %d\n", a, b, __min( a, b ) ); } Output The larger of 10 and 21 is 21 The smaller of 10 and 21 is 10 Floating-Point Support Routines See Also __max File: "C:\Program Files\Microsoft Visual Studio 10.0\VC\include\stdlib.h"
     175: #define __min(a,b)  (((a) < (b)) ? (a) : (b))
以其而始 2017-06-16
  • 打赏
  • 举报
回复
结帖了 谢谢各位
以其而始 2017-06-16
  • 打赏
  • 举报
回复
引用 4 楼 zhao4zhong1 的回复:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char htmls[]=
"htmlID=1001&MessageID=196&<rpc message-id=\"196\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
"<get><filter type=\"subtree\"><featurename istop=\"true\" type=\"mib\"><entPhysicalEntry position=\"iso.org.dod.internet.mgmt.mib-2.entityMIB.entityMIBObjects.entityPhysical.entPhysicalTable\"><entPhysicalSerialNum/><entPhysicalDescr/></entPhysicalEntry></featurename></filter></get></rpc>]]>]]>"
"htmlID=1001&MessageID=196&<rpc message-id=\"196\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
"<get><filter type=\"subtree\">"
"<featurename istop=\"true\" type=\"mib\">"
"    <EntityStateEntry position=\"iso.org.dod.internet.private.enterprises.Mgmt.Datacomm.EntityExtentMIB.EntityExtObjects.EntityState.EntityStateTable\">"
"        <EntityCpuUsage/>"
"        <EntityMemUsage/>"
"        <EntityTemperature/>"
"        <EntityCpuUsageThreshold/>"
"        <EntityMemUsageThreshold/>"
"        <EntityTemperatureThreshold/>"
"    </EntityStateEntry>"
"</featurename>"
"</filter>"
"</get>"
"</rpc>]]>]]>";
char *s,*p,*q,t[80+1];
int L;
int main() {
    s=(char *)htmls;
    while (1) {
        p=strstr(s,"<featurename ");
        if (!p) break;
        s=p;
        p=strstr(s,">");
        if (!p) break;
        s=p;
        p=strstr(s,"<");
        if (!p) break;
        q=strstr(p," ");
        if (!q) break;
        L=__min(80,q-p-1);
        strncpy(t,p+1,L);t[L]=0;
        printf("[%s]\n",t);
        s=q+1;
    }
    return 0;
}
//[entPhysicalEntry]
//[EntityStateEntry]
//
编译会出现 undefined reference to `_min'
赵4老师 2017-06-16
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char htmls[]=
"htmlID=1001&MessageID=196&<rpc message-id=\"196\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
"<get><filter type=\"subtree\"><featurename istop=\"true\" type=\"mib\"><entPhysicalEntry position=\"iso.org.dod.internet.mgmt.mib-2.entityMIB.entityMIBObjects.entityPhysical.entPhysicalTable\"><entPhysicalSerialNum/><entPhysicalDescr/></entPhysicalEntry></featurename></filter></get></rpc>]]>]]>"
"htmlID=1001&MessageID=196&<rpc message-id=\"196\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
"<get><filter type=\"subtree\">"
"<featurename istop=\"true\" type=\"mib\">"
"    <EntityStateEntry position=\"iso.org.dod.internet.private.enterprises.Mgmt.Datacomm.EntityExtentMIB.EntityExtObjects.EntityState.EntityStateTable\">"
"        <EntityCpuUsage/>"
"        <EntityMemUsage/>"
"        <EntityTemperature/>"
"        <EntityCpuUsageThreshold/>"
"        <EntityMemUsageThreshold/>"
"        <EntityTemperatureThreshold/>"
"    </EntityStateEntry>"
"</featurename>"
"</filter>"
"</get>"
"</rpc>]]>]]>";
char *s,*p,*q,t[80+1];
int L;
int main() {
    s=(char *)htmls;
    while (1) {
        p=strstr(s,"<featurename ");
        if (!p) break;
        s=p;
        p=strstr(s,">");
        if (!p) break;
        s=p;
        p=strstr(s,"<");
        if (!p) break;
        q=strstr(p," ");
        if (!q) break;
        L=__min(80,q-p-1);
        strncpy(t,p+1,L);t[L]=0;
        printf("[%s]\n",t);
        s=q+1;
    }
    return 0;
}
//[entPhysicalEntry]
//[EntityStateEntry]
//

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧