English 中文(简体)
NSXMLDocument written to xml
原标题:NSXMLDocument writing to .xml

Does anyone know why the file doesn t format correctly on the line "< taskinprogress>" its the 9th line. It puts "< project>" on the same line as "< taskinprogress> and I have no clue why. I want the "< project>" to be moved to the next line (without adding a character to a string).

<client_state>
    <platform>******PLATFORMNAME*******</platform>
    <OS_version>********OS VERSION*******</OS_version>
    <client_version>********client VERSION*******</client_version>
    <power_supply_connected>********POWER SUPPLY CONNECTED*******</power_supply_connected>
    <work_mode>********Work Mode*******</work_mode>
    <battery_level>********Battery Level*******</battery_level>
    <last_update>********Last Update*******</last_update>
    <task_in_progress>********task_in_progress*******<project>********Project*******</project>
        <application>********Application*******</application>
        <xml_file>********xml_file*******</xml_file>
        <task_id>********task_id*******</task_id>
        <create_time>********create_time*******</create_time>
        <receive_time>********receive_time*******</receive_time>
        <input>********input*******</input>
    </task_in_progress>
</client_state>

以下是我宣布所有节点和内容的法典。

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {

    NSXMLElement *client_state = [[NSXMLElement alloc] initWithName:@"client_state"];

    NSXMLElement *platform = [[NSXMLElement alloc] initWithName:@"platform"];
    [platform setStringValue:@"******PLATFORMNAME*******"];
    [client_state addChild:platform];
    [platform release];

    NSXMLElement *OS_version = [[NSXMLElement alloc] initWithName:@"OS_version"];
    [OS_version setStringValue:@"********OS VERSION*******"];
    [client_state addChild:OS_version];
    [OS_version release];

    NSXMLElement *client_version = [[NSXMLElement alloc] initWithName:@"client_version"];
    [client_version setStringValue:@"********client VERSION*******"];
    [client_state addChild:client_version];
    [client_version release];

    NSXMLElement *power_supply_connected = [[NSXMLElement alloc] initWithName:@"power_supply_connected"];
    [power_supply_connected setStringValue:@"********POWER SUPPLY CONNECTED*******"];
    [client_state addChild:power_supply_connected];
    [power_supply_connected release];

    NSXMLElement *work_mode = [[NSXMLElement alloc] initWithName:@"work_mode"];
    [work_mode setStringValue:@"********Work Mode*******"];
    [client_state addChild:work_mode];
    [work_mode release];

    NSXMLElement *battery_level = [[NSXMLElement alloc] initWithName:@"battery_level"];
    [battery_level setStringValue:@"********Battery Level*******"];
    [client_state addChild:battery_level];
    [battery_level release];

    NSXMLElement *last_update = [[NSXMLElement alloc] initWithName:@"last_update"];
    [last_update setStringValue:@"********Last Update*******"];
    [client_state addChild:last_update];
    [last_update release];

    //if(task in progress)

    NSXMLElement *task_in_progress = [[NSXMLElement alloc] initWithName:@"task_in_progress"];
    [task_in_progress setStringValue:@"********task_in_progress*******"];
    [client_state addChild:task_in_progress];
    [task_in_progress retain];
    [task_in_progress release];

    //start adding to inner task in progress

    NSXMLElement *project = [[NSXMLElement alloc] initWithName:@"project"];
    [project setStringValue:@"********Project*******"];
    [task_in_progress addChild:project];
    [project release];

    NSXMLElement *application = [[NSXMLElement alloc] initWithName:@"application"];
    [application setStringValue:@"********Application*******"];
    [task_in_progress addChild:application];
    [application release];

    NSXMLElement *xml_file = [[NSXMLElement alloc] initWithName:@"xml_file"];
    [xml_file setStringValue:@"********xml_file*******"];
    [task_in_progress addChild:xml_file];
    [xml_file release];

    NSXMLElement *task_id = [[NSXMLElement alloc] initWithName:@"task_id"];
    [task_id setStringValue:@"********task_id*******"];
    [task_in_progress addChild:task_id];
    [task_id release];

     NSXMLElement *create_time = [[NSXMLElement alloc] initWithName:@"create_time"];
     [create_time setStringValue:@"********create_time*******"];
     [task_in_progress addChild:create_time];
     [create_time release];

     NSXMLElement *receive_time = [[NSXMLElement alloc] initWithName:@"receive_time"];
     [receive_time setStringValue:@"********receive_time*******"];
     [task_in_progress addChild:receive_time];
     [receive_time release];

    NSXMLElement *input = [[NSXMLElement alloc] initWithName:@"input"];
    [input setStringValue:@"********input*******"];
    [task_in_progress addChild:input];
    [input release];

    [task_in_progress release];

    NSXMLDocument *xmlRequest = [NSXMLDocument documentWithRootElement:client_state];
    [client_state release];
    NSLog(@"XML Document
%@", xmlRequest);
     NSData *xmlData = [xmlRequest XMLDataWithOptions:NSXMLNodePrettyPrint];
    [xmlData writeToFile:@"client_state.xml" atomically:YES];
    [xmlRequest release];
    return 0;
}
最佳回答

我的空洞错误。 我是这样说的。 如果任何其他人都阅读了这一和奇怪的话,那么,如果NOT也具有价值,那么所有根基的节点就应当具有价值。 我正在把“和”任务——in_progress”作为节点,因此,我不得不按照声明删除这一行文:

//delete this:  Its a root, not a node w/ a value
 [task_in_progress setStringValue:@"********task_in_progress*******"];
问题回答

暂无回答




相关问题
How can I load a folders files into a ListView?

I d like to have a user select a folder with the FolderBrowserDialog and have the files loaded into the ListView. My intention is to make a little playlist of sorts so I have to modify a couple of ...

File Handling Issue

I am developing a tool in c#, at one instance I start writing into a xml file continuously using my tool,when i suddenly restart my machine the particular xml file gets corrupted, what is the reason ...

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Saving output of a for-loop to file

I have opened a file with blast results and printed out the hits in fasta format to the screen. The code looks like this: result_handle = open("/Users/jonbra/Desktop/my_blast.xml") from Bio.Blast ...

热门标签