1. xml学习
xml是文本标记语言,是用来表示,传输,存储文本信息的.表现显示跟html一样.由元素和节点组成.内容信息都存在节点里面
创建xml文档容器TiXmlDocument doc;
加载数据到容器中 char *pData = (char*)[data bytes];
doc.Parse(pData);
判断加载是否成功 if(!doc.error())
获取根元素 TiXmlElement *pRoot = doc.RootElement(); DeviceList为根元素
获取根元素下第一个孩子元素,必须用根元素对象去获取: TiXmlElement *pNode = pRoot ->FirstChildElement("ls");
获取孩子元素下节点内容: const char *pCount = pRoot->GetNodeText("allcount");
if(!doc.Error())
{
TiXmlElement * pRoot=doc.RootElement();
if(pRoot)
{
TiXmlElement * pNode= pRoot->FirstChildElement("Device");
while (pNode!=NULL)
{
const char *pDevId = pNode->GetNodeText("DevId");
pNode=pNode->NextSiblingElement("Device");
}
}
}
\n
xml里面还有另外一种:1;根元素没有字段 2.节点必须在元素里面,节点和元素必须是一对<>和>匹配 3.只有一个标记的是属性Attribute,没有<之类的表示 4.根元素或者元素下面第一个必须也是元素才能用FirstChildElement否则只能用NextSiblingElement 5.元素里面必须有节点或者元素或者属性才能为元素,
"
if(!doc.Error()){
TiXmlElement *pRoot = doc.RootElement();
const char *devId = pRoot->FirstChild()->Value();
if(devId!= NULL && pRoot!= NULL){
NSString *strOverlayEnable = @"";
NSString *strOverlayTran = @"";
NSString *strChannelId = @"";
NSString *strTimeVoerlayPosX =@"";
NSString *strTimeVoerlayPosY =@"";
NSString *strTimeVoerlayFormat =@"";
NSString *strTitleVoerlayPosX =@"";
NSString *strTitleVoerlayPosY =@"";
NSString *strTitleVoerlayTitle =@"";
TiXmlElement *pTimeNode = pRoot->NextSiblingElement("Video");
if(pTimeNode){
TiXmlElement *pOverlayNode = pTimeNode->FirstChildElement("Overlay");
const char *pOverlayEnable = pOverlayNode->Attribute("Enable");
const char *pOverlayTran = pOverlayNode->Attribute("Transparency");
const char *channelId = pOverlayNode->Attribute("ChanID");
if(pOverlayEnable != NULL){
if(pOverlayEnable != NULL){
strOverlayEnable = [NSString stringWithUTF8String:pOverlayEnable];
}
if(pOverlayTran != NULL){
strOverlayTran = [NSString stringWithUTF8String:pOverlayTran];
}
if(channelId != NULL){
strChannelId = [NSString stringWithFormat:@"%d",[[NSString stringWithUTF8String:channelId] intValue]+1] ;
}
}
if(pOverlayNode){
TiXmlElement *pOverlayTimeNode = pOverlayNode->FirstChildElement("TimeOverlay");
if(pOverlayTimeNode){
const char *timeVoerlayPosX = pOverlayTimeNode->Attribute("PosX");
const char *timeVoerlayPosY = pOverlayTimeNode->Attribute("PosY");
const char *timeVoerlayFormat = pOverlayTimeNode->Attribute("Format");
if(timeVoerlayPosX!=NULL){
strTimeVoerlayPosX = [NSString stringWithUTF8String:timeVoerlayPosX];
}
if(timeVoerlayPosY!=NULL){
strTimeVoerlayPosY = [NSString stringWithUTF8String:timeVoerlayPosY];
}
if(timeVoerlayFormat!=NULL){
strTimeVoerlayFormat = [NSString stringWithUTF8String:timeVoerlayFormat];
}
}
TiXmlElement *pOverlayTitleNode = pOverlayNode->FirstChildElement("TitleOverlay");
if(pOverlayTitleNode){
const char *titleVoerlayPosX = pOverlayTitleNode->Attribute("PosX");
const char *titleVoerlayPosY = pOverlayTitleNode->Attribute("PosY");
const char *titleVoerlayTitle = pOverlayTitleNode->Attribute("Title");