利用cmarkup类获取属性问题

奔跑前行 2010-01-20 11:38:20
我遇到问题: 就是遍历获取到了xml文件的每个元素的名称后, 找不到函数实现获取它的属性个数和属性名称

比如
<root>
<user id="111" name ="abc">
hello world;
</user>
</root>

请知道的 帮忙下!
主要是用CMarkUp类

顺便说明下: 不用GetAttrib 这个函数来实现 ,以为我是在遍历时候要获得相关的属性和值。
...全文
426 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
反方向的时间 2012-09-20
  • 打赏
  • 举报
回复
嘿 哥们 你解决了吗?我现在也是这个问题 可不可以把你解决的代码贴出来啊
<run-time-rule>
<item index='1' desc='定时清理' value='13:00;18:00;20:00' />
<item index='2' desc='周期清理' value='30' />
</run-time-rule>
我这个也是要解析里边元素的属性 但是不知道怎么弄
我用getattrib()获取属性 打印出来的总是空白,,郁闷啊
aoyihuashao 2010-01-21
  • 打赏
  • 举报
回复
至于要获取总共有几个属性。
int n =0
while(xml.GetAttribName(n))
{
n++;
}
//到这里,n就是属性个数了啊。
aoyihuashao 2010-01-21
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 fly0622 的回复:]
在明确点  说吧

  <root>
<user  id="111" name ="abc">
hello world;
</user>
</root>

只要能把 id="111" 和name ="abc">抓出来也ok的
[/Quote]

上面那段不是写着的啊,
You can loop through beginning at n=0 and incrementing n until it returns an empty string to discover all of the attributes an element has.

通过自增属性位置遍历属性表啊。
for(int n = 0 ;;n++)
{
xml.GetAttribName(n);
//如果是空字符串,就表示遍历完了啊。否则就做你要做的处理啊。
}
奔跑前行 2010-01-21
  • 打赏
  • 举报
回复
在明确点 说吧

<root>
<user id="111" name ="abc">
hello world;
</user>
</root>

只要能把 id="111" 和name ="abc">抓出来也ok的
奔跑前行 2010-01-21
  • 打赏
  • 举报
回复
楼上几位说的 ,我知道 官网上的说明,我也查了很多资料。就是在GetAttribName,GetAttrib这个几个函数都是无法直接就获取到属性的数量。只能模糊是模糊的获取而已。 cmarkup类的方法获取属性的就是这些吧。
大家还有说明可以帮忙的???
我现在最想就是如何 获取 属性的个数。

2天后结贴
奔跑前行 2010-01-21
  • 打赏
  • 举报
回复
我 实现的主要目的就是: 想把xml转化为 tree control 的 树状现实 并且把 属性一起附上去的。。。。。
奔跑前行 2010-01-21
  • 打赏
  • 举报
回复
这个我知道这么处理,看来 camrkup类只能这样子用了。。。。。我看官网的那个解析器 它是能够 分割出 id="111" 这样的语句处理。。。不过还是谢谢各位了 看看还有没有更好的建议。。。。明天结贴。。
奔跑前行 2010-01-20
  • 打赏
  • 举报
回复
奇怪 没人会的吗???
hhwei1985 2010-01-20
  • 打赏
  • 举报
回复
up
aoyihuashao 2010-01-20
  • 打赏
  • 举报
回复
VC CMarkup所有方法说明

http://www.cnblogs.com/aoyihuashao/archive/2010/01/20/1652804.html
tzxx 2010-01-20
  • 打赏
  • 举报
回复
CMarkup GetAttribName Method
http://www.firstobject.com/dn_markGetAttribName.htm
看起来好像可以用这个实现,最近在用这个类,不过没LZ这种需求
aoyihuashao 2010-01-20
  • 打赏
  • 举报
回复
CMarkup GetAttribName Method
MCD_STR GetAttribName( int n ) const;Call GetAttribName to get the attribute name of the zero-based nth attribute of the main position element. If there is no current position, it returns an empty string regardless of n. If the child position element has no nth attribute, it returns an empty string. This is used to query the attributes that an element has. You can loop through beginning at n=0 and incrementing n until it returns an empty string to discover all of the attributes an element has.

Here is an example of getting the first attribute of this small sample document:

<ROOT customcode="35"/>xml.ResetPos();
xml.FindElem();
str sAttribName = xml.GetAttribName( 0 ); // "customcode"
str sValue = xml.GetAttrib(sAttribName); // "35"SetAttrib also works when the main position is a processing instruction node. See Node Methods in CMarkup.
  • 打赏
  • 举报
回复
好像不行
奔跑前行 2010-01-20
  • 打赏
  • 举报
回复
没人知道吗?? 自己顶一下。。。。

3,055

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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