我想用客观C对例如一些行动 修改XML属性,我对屏幕按钮,我的XML标记是修改属性
MYNODE ATTRIBUTE1 =“” attribute2 =“”属性3 =“” /mynode
如果属性3的初始值为NO,在轻敲按钮上我想将其更改为YES并将其写入到项目目录中的xml文件中。 请帮助我,如果有人知道这一点。 我曾尝试使用GDataXML addattribute方法,但无法修改标记。
我想用客观C对例如一些行动 修改XML属性,我对屏幕按钮,我的XML标记是修改属性
MYNODE ATTRIBUTE1 =“” attribute2 =“”属性3 =“” /mynode
如果属性3的初始值为NO,在轻敲按钮上我想将其更改为YES并将其写入到项目目录中的xml文件中。 请帮助我,如果有人知道这一点。 我曾尝试使用GDataXML addattribute方法,但无法修改标记。
无法编辑Objective-c中的XML文件。如果你想这样做,那么你需要创建自己的XML文件,或者你可以将标签附加到现有的XML。 请参考下面的代码,在其中创建我自己的xml以附加图像的字节数组&,并将其添加到原始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];
您可以根据您的要求对其进行修改。
谢谢,我会试一试 –
确定您可以尝试这个&让我知道你是否面临任何问题。 – Girish
发布一些代码并解释它失败的位置 –
GDataXMLElement * node = [GDataXMLNode elementwithName:@“mynode”]; GDataXMLElement * attribute = [GDataXMLNode attributewithName:@“attribute3 stringValue:@”Yes“]; [node addAttribute:attribute];在此之后,我正在使用writeToFile自动写入xmlfile。 –