我正在尝试将libxml2移植到android.When我使用带空格的文件路径 (例如path =" / storage / emulated / 0 / sdcard / New XML.xml"),打开xml文件失败。但是如果我使用不带空格的路径(例如" / storage) /emulated/0/sdcard/NewXML.xml"。解析文件成功。请帮我解决这个问题。
以下是示例代码:
#include <stdio.h>
#include <libxml/xmlreader.h>
static void
processNode(xmlTextReaderPtr reader) {
const xmlChar *name, *value;
name = xmlTextReaderConstName(reader);
if (name == NULL)
name = BAD_CAST "--";
value = xmlTextReaderConstValue(reader);
printf("%d %d %s %d %d",
xmlTextReaderDepth(reader),
xmlTextReaderNodeType(reader),
name,
xmlTextReaderIsEmptyElement(reader),
xmlTextReaderHasValue(reader));
if (value == NULL)
printf("\n");
else {
if (xmlStrlen(value) > 40)
printf(" %.40s...\n", value);
else
printf(" %s\n", value);
}
}
static void streamFile(const char *filename) {
xmlTextReaderPtr reader;
int ret;
reader = xmlReaderForFile(filename, NULL, 0);
if (reader != NULL) {
ret = xmlTextReaderRead(reader);
while (ret == 1) {
processNode(reader);
ret = xmlTextReaderRead(reader);
}
xmlFreeTextReader(reader);
if (ret != 0) {
fprintf(stderr, "%s : failed to parse\n", filename);
}
} else {
fprintf(stderr, "Unable to open %s\n", filename);
}
}
int main() {
const char path[64] = "/storage/emulated/0/sdcard/New XML.xml"
streamFile(path);
xmlCleanupParser();
xmlMemoryDump();
return(0);
}
答案 0 :(得分:0)
对您的空间进行编码......
xmlReaderForFile filename:文件或URL
答案 1 :(得分:0)
您需要在文件名中转义空格。 试试
bazel query