D Bus学习(九):利用XML定义D Bus之Singal收发例子
在前面我们学习了使用Glib的高程捆绑方式的method的收发,现在学习singal的收发,xml例子如下
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/com/wei/MyObject">
<interface name="com.wei.MyObject.Sample">
<method name="Test">
<arg name="x" type="u" direction="in" />
<arg name="d_ret" type="d" direction="out" />
</method >
<signal name="Hello">
<arg name="w_dialog" type="s" />
</signal>
</interface >
</node >
在前面我们已经学习了方法Test的处理,现在增加一个信号Hello,为了是的处理方式更为简洁,这个信号只带来一个叫做w_dialog的字符串。同样我们使用dbus-binding-tool工具分别生成了server的头文件wei_server2.h和client的头文件wei_client2.h。(操作方式,请参阅上两次学习)。
Server的编写
查看wei_server2.h,和之前只有method的相比,只有稍稍的改动,在对象的info中,增加了Hello的说明。如下:
... ...
const DBusGObjectInfo dbus_glib_com_wei_object_info = {
0,
dbus_glib_com_wei_methods,
1,
"com.wei.MyObject.Sample\0Test\0S\0x\0I\0u\0d_ret\0O\0F\0N\0d\0\0\0",
"com.wei.MyObject.Sample\0Hello\0\0"
,
"\0"
};
我们需要对象中增加相关的代码,头文件com_wei_myobject2.h如下:
#ifndef WEI_COM_WEI_MYOBJECT2_H
#define WEI_COM_WEI_MYOBJECT2_H
typedef struct ComWeiMyObject2 ComWeiMyObject2;
typedef struct ComWeiMyObject2Class ComWeiMyObject2Class;
struct ComWeiMyObject2
{
GObject parent;
};
struct ComWeiMyObject2Class
{
GObjectClass parent;
};
#define COM_WEI_MYOBJECT2_TYPE (com_wei_myobject2_get_type())
GType com_wei_myobject2_get_type(void);
gboolean com_wei_test(ComWeiMyObject2 * obj ,
相关文档:
网上提供的一些方法比较简单,无法适应XML文件的动态变化 ,没办法只能自己查文档写,总算没浪费时间,用的时候别忘了加#import
"msxml4.dll"这个动态链接库网上很好找,自己找一下,希望能帮助需要的朋友,困了
::CoInitialize(NULL);
//初始化COM
MSXML2::IXMLDOMDocumentPtr pDoc;
......
对于带有表空间xmlns的xml文件的解析,用正常解析文件的方法总是失效,不起作用,无法获得元素。
下面给出两种方法解析此类文件:
1.按正常解析xml文件的方法,需要注意几点:
获取元素Element,不可使用函数:document.selectNodes("//region");
只可以先取到根元素,一级一级往下取,eg:
Element root = document.g ......
1.要解析的XML文件如下:
<?xml version="1.0" encoding="GB2312"?>
<?xml-stylesheet href="student.xsl" type="text/xsl"?>
<StudentInfo>
<student>
<name>达内</name>
<sex>男</sex>
<lesson>
  ......
工作中遇到需要合并XML的问题,遂从网上查找相关资料,
1、 《 XML merging made easy
》
2 、《java中合并xml文档的设计与实现
》
测试后发现均不符合实际需求,实际需求如下:
file1.xml:
<root>
<a>
<b name="1"/>
</a>
<d /& ......
Retrieving an XML document using Ajax
http://www.javascriptkit.com/dhtmltutors/ajaxgetpost3.shtml
When making a server request in Ajax, the data returned can be in either
plain text/html, or an XML document instead. The later is technically
just a text file as well, but with s ......