xml相关知识

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");

            }

        }

    }

<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<DeviceList>\n<Device>\n<DevId>5685895-CH-1</DevId>\n<DevName>5685895</DevName>\n<DevGroupName>5685895</DevGroupName>\n<OnLine>2</OnLine>\n<WithPTZ>1</WithPTZ>\n<DoubleStream>1</DoubleStream>\n<RecStatus>0</RecStatus>\n<VisitStreamOption>0</VisitStreamOption>\n<DevType>201</DevType>\n<OSS>0</OSS>\n<LoginName>admin</LoginName>\n<LoginPassword>a123456</LoginPassword>\n</Device>\n<Device>\n<DevId>5685895-CH-2</DevId>\n<DevName>5685895</DevName>\n<DevGroupName>5685895</DevGroupName>\n<OnLine>2</OnLine>\n<WithPTZ>1</WithPTZ>\n<DoubleStream>1</DoubleStream>\n<RecStatus>0</RecStatus>\n<VisitStreamOption>0</VisitStreamOption>\n<DevType>201</DevType>\n<OSS>0</OSS>\n<LoginName>admin</LoginName>\n<LoginPassword>a123456</LoginPassword>\n</Device>\n<Device>\n<DevId>5685895-CH-3</DevId>\n<DevName>5685895</DevName>\n<DevGroupName>5685895</DevGroupName>\n<OnLine>2</OnLine>\n<WithPTZ>1</WithPTZ>\n<DoubleStream>1</DoubleStream>\n<RecStatus>0</RecStatus>\n<VisitStreamOption>0</VisitStreamOption>\n<DevType>201</DevType>\n<OSS>0<"… 0x000000011bbe8000

xml里面还有另外一种:1;根元素没有字段  2.节点必须在元素里面,节点和元素必须是一对<>和</>匹配 3.只有一个标记的是属性Attribute,没有<之类的表示 4.根元素或者元素下面第一个必须也是元素才能用FirstChildElement否则只能用NextSiblingElement 5.元素里面必须有节点或者元素或者属性才能为元素, <DevId>5685895</DevId>不能是元素 6. <DevId>5685895</DevId>为pRoot->FirstChild()

"<DevId>5685895</DevId>\n<Video ChannelId=\"0\">\n<Capture\nBrightness=\"\"\nContrast=\"\"\nSaturation=\"\"\nSharpness=\"\"\nDayNight=\"\"\nWhiteBalance=\"\"\nBackLight=\"\"\nSwitch2A=\"\"\nBinningSkip=\"\"\nTVSystem=\"\"\nHFlip=\"\"\nVFlip=\"\"\nTNF=\"\"\nSNF=\"\"\nVSTAB=\"\"\nLDC=\"\"\nFD=\"\"\nIrcutMode=\"\"\nIrcutSensitivity=\"\"\nIrcutNightStartTime=\"\"\nIrcutNightEndTime=\"\"\n/>\n<Encode>\n<EncodeConfig\nStream=\"\"\nResolution=\"\"\nEncodeFormat=\"\"\nBitRateControl=\"\"\nInitquant=\"\"\nBitRate=\"\"\nFrameRate=\"\"\n/>\n<EncodeConfig\nStream=\"\"\nResolution=\"\"\nEncodeFormat=\"\"\nBitRateControl=\"\"\nInitquant=\"\"\nBitRate=\"\"\nFrameRate=\"\"\n/>\n</Encode>\n<JpegConfig\nEnable=\"\"\nStream=\"\"\nQuality=\"\"\nFramerate=\"\"\n/>\n<Overlay\nEnable=\"1\"\nTransparency=\"3\"\nChanID=\"0\"\n>\n<TimeOverlay\nPosX=\"0\"\nPosY=\"0\"\nFormat=\"yyyy-mm-dd hh:mm:ss\"\n/>\n<TitleOverlay\nPosX=\"1\"\nPosY=\"1\"\nTitle=\"513130CEA2B9E2204832363420B4F3C2EDC2B7\"\n/>\n</Overlay>\n</Video>\n\n" 0x000000011eb99c10

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");

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容