objective-c xmlchar数据类型如何工作

时间:2022-09-06 16:36:30

In objective c how does an xmlchar data type work? I can't seem to find any API documentation. Specifically my declaration looks like:

在目标c中,xmlchar数据类型如何工作?我似乎无法找到任何API文档。具体来说,我的声明如下:

    const xmlChar **attributes

Am I classifying this correctly by saying it's an objective c data type or is it specific to cocoa or just C?

我是通过说它是一个客观的c数据类型还是特定于cocoa或只是C来正确分类?

2 个解决方案

#1


You can see the declaration xmlChar in xmlString.h found in libxml2 library as:

您可以在libxml2库中找到xmlString.h中的声明xmlChar:

typedef unsigned char xmlChar;

Now for xmlChar to NSString conversion

现在为xmlChar转换为NSString

xmlChar *str = (unsigned char *)"I am to be converted";
NSString *convertedString = [NSString stringWithUTF8String:(const char *)str];

from NSString to xmlChar conversion;

从NSString到xmlChar的转换;

NSString *str = @"I am to be converted";
xmlChar *convertedString = (xmlChar *)[str UTF8String];

#2


I don't think that Objective-C has any sort of xmlChar data type. In Cocoa, you will generally use an NSXMLParser, which just uses NSString. Are you perhaps thinking of libxml2? In that case, it's simply defined as an unsigned char representing a UTF-8 octet (to help the compiler give warnings if you try to cast it to a char). You can generally treat an xmlChar * like a regular char *, as long as you keep in mind that it's UTF-8 encoded rather than in ASCII (so, truncating it may give invalid characters, comparing values to sort them won't work unless you implement locale-aware comparisons, etc).

我不认为Objective-C有任何类型的xmlChar数据类型。在Cocoa中,您通常会使用NSXMLParser,它只使用NSString。你是否想过libxml2?在这种情况下,它只是被定义为表示UTF-8八位字节的unsigned char(如果你试图将它转换为char,则帮助编译器发出警告)。您通常可以将xmlChar *视为常规char *,只要您记住它是UTF-8编码而不是ASCII(因此,截断它可能会产生无效字符,比较值以排序它们将无法工作,除非您实现区域设置感知比较等)。

#1


You can see the declaration xmlChar in xmlString.h found in libxml2 library as:

您可以在libxml2库中找到xmlString.h中的声明xmlChar:

typedef unsigned char xmlChar;

Now for xmlChar to NSString conversion

现在为xmlChar转换为NSString

xmlChar *str = (unsigned char *)"I am to be converted";
NSString *convertedString = [NSString stringWithUTF8String:(const char *)str];

from NSString to xmlChar conversion;

从NSString到xmlChar的转换;

NSString *str = @"I am to be converted";
xmlChar *convertedString = (xmlChar *)[str UTF8String];

#2


I don't think that Objective-C has any sort of xmlChar data type. In Cocoa, you will generally use an NSXMLParser, which just uses NSString. Are you perhaps thinking of libxml2? In that case, it's simply defined as an unsigned char representing a UTF-8 octet (to help the compiler give warnings if you try to cast it to a char). You can generally treat an xmlChar * like a regular char *, as long as you keep in mind that it's UTF-8 encoded rather than in ASCII (so, truncating it may give invalid characters, comparing values to sort them won't work unless you implement locale-aware comparisons, etc).

我不认为Objective-C有任何类型的xmlChar数据类型。在Cocoa中,您通常会使用NSXMLParser,它只使用NSString。你是否想过libxml2?在这种情况下,它只是被定义为表示UTF-8八位字节的unsigned char(如果你试图将它转换为char,则帮助编译器发出警告)。您通常可以将xmlChar *视为常规char *,只要您记住它是UTF-8编码而不是ASCII(因此,截断它可能会产生无效字符,比较值以排序它们将无法工作,除非您实现区域设置感知比较等)。