修改objective c中xml标签的属性 [英] Modify attribute of xml tag in objective c

查看:31
本文介绍了修改objective c中xml标签的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在某些操作上使用目标 c 修改 xml 属性例如,我在屏幕上有按钮,我的 xml 标签是

I want to modify xml attribute using objective c on some action for example, i have button on screen and my xml tag is

mynode attribute1=""attribute2=""attribute3=""/我的节点

mynode attribute1="" attribute2="" attribute3="" /mynode

如果attribute3的初始值为NO,点击按钮时我想将其更改为YES并将其写入项目目录中的xml文件.如果有人知道这件事,请帮助我.我曾尝试使用 GDataXML addattribute 方法,但无法修改标签.

if initial value of attribute3 is NO, on tapping button i want to change it to YES and write it to xml file which is in projects directory. Please help me if anyone know about this. I have tried using GDataXML addattribute method, but not able to modify tag.

推荐答案

无法在 Objective - c 中编辑 XML 文件.如果你想这样做,那么你需要创建你自己的 xml 文件,或者你可以将标签附加到现有的 xml.请参考以下代码,其中我创建了自己的 xml 以附加图像的字节数组 &将其添加到原始 xml 中.

It is not possible to edit the XML file in Objective - c. If you want to do this, then you needs to create your own xml file or you can append the tags to the existing xml. Please refer the following code where I am created my own xml to append the bytes array of a image & adding it to the original xml.

//Encode all the data and get the XML string 
            NSString *theXML = [[NSString alloc] 
                                initWithBytes: [clipSvgData bytes] 
                                length:[clipSvgData length] 
                                encoding:NSUTF8StringEncoding];

            //Returns the substring of an main xml file by excluding the extra xml tags
            NSString *startTag = @"<svg";
            NSString *endTag = @"</svg>";
            NSString *responseString;

            NSScanner *scanner = [[NSScanner alloc] initWithString:theXML];
            [scanner scanUpToString:startTag intoString:nil];
            scanner.scanLocation += [startTag length];
            [scanner scanUpToString:endTag intoString:&responseString];
            [scanner release];

            //Remove the SVG tag from main xml
            NSString *startTag1 = @">";
            NSString *endTag1 = @"</svg>";
            NSString *responseString1;

            NSScanner *scanner1 = [[NSScanner alloc] initWithString:[NSString stringWithFormat:@"<svg %@ </svg>",responseString]];
            [scanner1 scanUpToString:startTag1 intoString:nil];
            scanner1.scanLocation += [startTag1 length];
            [scanner1 scanUpToString:endTag1 intoString:&responseString1];
            [scanner1 release];

    NSString *strSVGNode = [NSString stringWithFormat:@"<svg version=\"1.1\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"%fpx\" y=\"%fpx\" width=\"%fpx\" height=\"%fpx\" viewBox=\"0 0 141.73 141.73\" enable-background=\"new 0 0 141.73 141.73\"  xml:space=\"preserve\" preserveAspectRatio=\"none\">", imgXPos, imgYPos, imgWidth, imgHeight];

    NSString *strClipXml = [NSString stringWithFormat:@"%@ %@ </svg></g>",strSVGNode ,responseString1];

    //Add the created SVG as new node in main SVG file.
    GDataXMLNode *clipNode = [GDataXMLNode textWithStringValue:[NSString stringWithFormat:@"%@",strClipXml]];
    [xmlDocument.rootElement addChild:clipNode];

您可以根据需要修改它.

You can modify it as per your requirement.

这篇关于修改objective c中xml标签的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆