Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cinek

macrumors 6502
Original poster
will this xml file be ok to parse it with an xml parser?

Code:
<?xml version="1.0" ?>
<page assetid="10204">
  <metadata>
    <dc>
      <created>2010-05-20 16:46:46</created>
      <description>Professional Services</description>
      <modified>13/04/2011 17:04:01</modified>
    </dc>

  </metadata>
  <standfirst></standfirst>
  <title>Business Services</title>
  <body>
    <[!CDATA[
      
		<div id="content" class="standard">
<h1>Business Services</h1>
<!-- call to action list : -->
<!-- no call to action's declared (globals_metadata_action.after: , replacement_root_node: , root_nodes: 21404,87) -->
<div id="content_div_10206">

<p>we offer a wide range of services to businesses of all sizes and types, which will help you:</p>

<ul>
  <li>develop new and innovative products and services</li>

  <li>increase efficiency and grow your business</li>

  <li>upskill your staff to meet the demands of an ever-changing market and increased competition.</li>
</ul>

<p>For further information on how we can help your business, please click on one of the left hand links.</p>

</div>


<!-- no call to action's declared (globals_metadata_action.after: , replacement_root_node: , root_nodes: 21404,87) --></div>
 
    ]]>
  

</body>
</page>

or does it have to be something like:

Code:
<CATALOG><PLANT><COMMON>Bloodroot</COMMON><BOTANICAL>Sanguinaria canadensis</BOTANICAL><ZONE>4</ZONE><LIGHT>Mostly Shady</LIGHT><PRICE>$2.44</PRICE><AVAILABILITY>031599</AVAILABILITY></PLANT><PLANT>
 
Neither of your examples are well-formed. See http://www.w3schools.com/xml/xml_validator.asp.

(Or use this code.) Good luck 🙂

Code:
// clang -W -Wall -framework Foundation xmlvalidator.m
#import <Foundation/Foundation.h>

int main(int argc, char const *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSError *error = nil;

    if (argc == 2) {
        NSData *data = [NSData dataWithContentsOfFile:[NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding]
                                              options:NSDataReadingUncached
                                                error:&error];
        if (!error) {
            NSXMLParser *parser = [[[NSXMLParser alloc] initWithData:data] autorelease];
            [parser parse];
            error = [parser parserError];
            if (error) {
                NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithCapacity:8];
                [userInfo addEntriesFromDictionary:error.userInfo];
                [userInfo setValue:[NSNumber numberWithInteger:parser.lineNumber] forKey:@"line"];
                [userInfo setValue:[NSNumber numberWithInteger:parser.columnNumber] forKey:@"column"];
                error = [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo];
            }
        }
    } else {
        error = [NSError errorWithDomain:@"xmlvalidator"
                                    code:1
                                userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"usage: xmlvalidator filename.xml", NSLocalizedDescriptionKey, nil]];
    }

    if (error) {
        NSLog(@"%@", error);
    }

    [pool drain];

    return 0;
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.