Probleme avec le parser xml de Core Foudation...

SuperCed

Membre expert
Club iGen
20 Juin 2001
1 353
72
46
superced.rb38.eu
J'ai un probleme avec le parser xml de Core Foundation.

Voici le code, j'ai commente pour montrer la ou il y a un crash. J'ai recopier l'exemple fournit par la doc sur le site d'Apple.

L'arbre ne se construit pas, il reste a NULL. Pourquoi?



- (void)readXMLFile {
char cheminDAcces[4096];
const char *chem;
NSString *path = [[NSBundle mainBundle] bundlePath];
chem = [path fileSystemRepresentation];
strcpy(cheminDAcces, chem);
unsigned int longueurChemin = strlen(cheminDAcces);
unsigned int nb = 0;
unsigned int i=0;
unsigned int j=0;
for (i=0;i<longueurChemin;i++) {
if (cheminDAcces == '/') {
nb ++;
}
}
i=0;
j=0;
while (i<nb) {
if (cheminDAcces[j] == '/') {
i++;
}
j++;
}
cheminDAcces[j] = '\0';
strcat(cheminDAcces, kXMLFileName);
NSLog(@"%s",cheminDAcces);

CFStringRef thePosixPath = CFStringCreateWithCString(NULL, cheminDAcces, kCFStringEncodingMacRoman);
CFURLRef sourceURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, thePosixPath, kCFURLPOSIXPathStyle, false);
CFShow(sourceURL);

CFXMLTreeRef xmlTreeNode;
CFDataRef xmlData;
CFXMLTreeRef cfXMLTree;

CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,
sourceURL, &xmlData, NULL, NULL, NULL);

//cfXMLTree = CFXMLTreeCreateFromData(kCFAllocatorDefault, xmlData, sourceURL, kCFXMLParserNoOptions, kCFXMLNodeCurrentVersion);
cfXMLTree = CFXMLTreeCreateWithDataFromURL (kCFAllocatorDefault, sourceURL, kCFXMLParserSkipWhitespace, kCFXMLNodeCurrentVersion);

CFXMLNodeRef xmlNode;
CFIndex childCount;
int index;

if (cfXMLTree == NULL) {
NSLog(@"Video-party : cfXMLTree empty"); // pass here
}
childCount = CFTreeGetChildCount(cfXMLTree); // crash here

for (index = 0; index < childCount; index++ ) {
xmlTreeNode = CFTreeGetChildAtIndex(cfXMLTree, index) ; // and crash here
xmlNode = CFXMLTreeGetNode(xmlTreeNode);
CFShow(CFXMLNodeGetString(xmlNode));
}
}

J'ai essaye 2 fonctions differentes pour creer l'arbre et ca donne le meme resultat.
L'url affichee a l'air correcte...

Avez-vous une autre solution pour lire un document xml?