在libxml和c中工作,我有这个代码snippit:
if (!xmlStrcmp(cur->name, (const xmlChar *)"headline")) {
key = xmlNodeListGetString(doc,cur->xmlChildrenNode,1);
conf_var.headline=key;
xmlFree(key);
}
elseif (!xmlStrcmp(cur->name, (const xmlChar *)"para")) {
key = xmlNodeListGetString(doc,cur->xmlChildrenNode,1);
conf_var.para=key;
xmlFree(key);
}
Run Code Online (Sandbox Code Playgroud)
当我编译它时,我收到以下错误:things.c:29:59:error:expected';' 在'{'之前
引用的行是elseif行.我真的不知道这里有什么问题,因为在if命令中,相同的代码位于其上方.这有什么不对?
我不小心从我的系统中删除了libxml2.dylib文件(Xcode无法通过"选择框架..."找到它).我怎样才能找回来?
我做了以下操作:
- 通过"构建阶段"选项卡插入libxml2.dylib
- 从构建阶段
删除它 - 从项目中删除它
- 选择"移动到垃圾箱"
- 清除垃圾
问候莱昂
我下载了一个名为AePubReader的开源epub阅读器,它的工作正常.但是当我试图在xcode 4.6中集成我的应用程序时,由于ARC而显示出很多错误.所以我选择了这些文件并设置了"-fno-objc-arc"然后它显示错误,如#include <libxml/tree.h> not found![this is the error i got ][1]
$(SDK_DIR)"/ usr/include/libxml2我添加了这一行然后该问题得到解决,但之后它显示"43错误"类似"Apple Mach-O Linker Error"的大部分内容它们与xml文件有关
我的错误消息
体系结构i386的未定义符号:"_ htmlParseDoc",引用自: - CXHTMLDocument.o中的[CXHTMLDocument initWithXHTMLString:options:error:]
"_htmlReadMemory",引自: - [CXHTMLDocument initWithXHTMLData:encoding:options:error:]在CXHTMLDocument.o"_xmlAddChild"中,引自: - [CXMLDocument(CXMLDocument_CreationExtensions)addChild:]在CXMLDocument_CreationExtensions.o中 - [CXMLElement(CXMLElement_CreationExtensions)addChild :] CXMLElement_CreationExtensions.o - CXMLElement_CreationExtensions.o中的[CXMLElement_CreationExtensions] setStringValue:]"_ xmlAddPrevSibling",引自: - CXMLDocument_CreationExtensions.o"_xmlCopyNode"中的[CXMLDocument(CXMLDocument_CreationExtensions)insertChild:atIndex:],引用自: - [ CXMLNode copyWithZone:]在CXMLNode.o中
"_xmlDocDumpFormatMemory", referenced from:
-[CXMLDocument description] in CXMLDocument.o
Run Code Online (Sandbox Code Playgroud)
"_xmlDocDumpMemory",引用自: - CXMLDocument.o中的[CXMLDocument XMLDataWithOptions:]"_xmlDocGetRootElement",引自: - CXMLDocument.o中的[CXMLDocument initWithData:encoding:options:error:] - CXMLDocument.o中的[CXMLDocument rootElement]" _xmlDocSetRootElement",引自:CXMLNode_CreationExtensions.o中的+ [CXMLNode(CXMLNode_CreationExtensions)documentWithRootElement:] - CXHTMLDocument.o"_xmlFree"中的[CXHTMLDocument initWithXHTMLString:options:error:],引用自: - CXMLDocument.o中的[CXMLDocument XMLDataWithOptions:] - CXMLDocument.o中的[CXMLDocument描述]"_xmlFreeDoc",引自: - CXMLDocument.o中的[CXMLDocument dealloc]"_xmlFreeNode",引用自: - CXMLNode.o中的[CXMLNode dealloc]"_xmlGetCharEncodingName",引用自: - [ CXHTMLDocument:initWithXHTMLString:options:error:]在CXHTMLDocument.o"_xmlGetLastError"中,引用自: - …
我有一个使用libxml2 writer将XML文档写入缓冲区的函数,但是当我尝试使用xmlParseMemory从内存中解析文档时,它仅返回解析器错误。我也尝试将文档写入文件并使用xmlParseFile对其进行解析,并成功解析。
这就是我初始化xml文档的writer和缓冲区的方式。
int rc, i = 0;
xmlTextWriterPtr writer;
xmlBufferPtr buf;
// Create a new XML buffer, to which the XML document will be written
buf = xmlBufferCreate();
if (buf == NULL)
{
printf("testXmlwriterMemory: Error creating the xml buffer\n");
return;
}
// Create a new XmlWriter for memory, with no compression.
// Remark: there is no compression for this kind of xmlTextWriter
writer = xmlNewTextWriterMemory(buf, 0);
if (writer == NULL)
{
printf("testXmlwriterMemory: Error creating the xml writer\n");
return;
} …Run Code Online (Sandbox Code Playgroud) 我正在使用LibXML解析一个简单的jhove输出.但是,我没有得到我期望的价值.这是代码:
use feature "say";
use XML::LibXML;
my $PRSR = XML::LibXML->new();
my $xs=<DATA>;
say $xs;
my $t1 = $PRSR->load_xml(string => $xs);
say "1:" . $t1->findvalue('//date');
$xs=<DATA>;
say $xs;
$t1 = $PRSR->load_xml(string => $xs);
say "2:" . $t1->findvalue('//date');
__DATA__
<jhove xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://hul.harvard.edu/ois/xml/ns/jhove" xsi:schemaLocation="http://hul.harvard.edu/ois/xml/ns/jhove http://hul.harvard.edu/ois/xml/xsd/jhove/1.3/jhove.xsd" name="Jhove" release="1.0 (beta 3)" date="2005-02-04"><date>2006-10-06T09:11:34+02:00</date></jhove>
<jhove><date>2006-10-06T09:11:34+02:00</date></jhove>
Run Code Online (Sandbox Code Playgroud)
如您所见,"1:"行返回一个空字符串,而"2:"返回预期日期.jhove-root-element中的什么使xpath查询无法正常工作?我甚至在XML-Spy中尝试过它,即使有完整的标题也可以.
编辑:当我从根元素中删除xmlns属性时,xpath查询工作.但那怎么可能呢?
我正在使用R中的xml2包来解析一些非常大的xml文件。read_xml()成功加载了大文件,但是当我尝试使用xml_find_all()时,出现“错误:内存分配失败:节点集命中限制越来越大。” 我假设此限制是在libxml2中设置的,也许是在XPATH_MAX_NODESET_LENGTH var中设置的?所以也许这不是xml2包本身的问题。但是xml2内是否有解决方案?我尝试删除节点并释放内存而没有运气。谢谢。
如何使用libxml2使用xpath从C++中的xml文件中检索节点和属性值?
在此先感谢Bhargava
我之前成功使用xmlTextReaderGetAttribute(来自xmlsoft.org),但API文档要求我释放返回的内容xmlChar*.现在我的应用程序在第二次(第一次传递null)调用时崩溃free(),如下所示:
xmlTextReaderPtr reader = null;
xmlChar *attribVal = null;
//blah...
if (xmlTextReaderAttributeCount(reader) > 0) {
free((attribVal));
attribVal = xmlTextReaderGetAttribute(reader, (const xmlChar*)"super-Attrib");
if (xmlStrcasecmp(attribVal, (const xmlChar*)"monoMega-Attrib") == 0) {
free((attribVal));
Run Code Online (Sandbox Code Playgroud)
我的项目是用C++ 编写的,但是libxml2和xmlsoft.org的所有例子都使用标准C.
我一直在尝试解析London Underground Linestatus XML“提要”-收效甚微。我本来希望使用XPath可以“轻松”,但是我得到的是空节点。
我相当确定我不会正确处理uk名称空间。
这是我的(相当简单的代码):
import libxml2
from urllib2 import urlopen
data = urlopen('http://cloud.tfl.gov.uk/TrackerNet/LineStatus').read()
try:
doc = libxml2.parseDoc(data)
except (libxml2.parserError, TypeError):
print "Problems loading XML"
context = doc.xpathNewContext()
context.xpathRegisterNs("uk", "http://webservices.lul.co.uk")
record_nodes = context.xpathEval('//uk:LineStatus')
for node in record_nodes:
print "******************************"
Run Code Online (Sandbox Code Playgroud)
record_nodes循环被忽略。xml已正确解析。
有人可以说明一下吗?
以下代码
Xml.Node* node = new Xml.Node (null, "name");
node->set_content("&");
Run Code Online (Sandbox Code Playgroud)
产生以下错误:
错误:未终止的实体引用
这是一个错误还是我做错了什么?
大字符和小字符都可以正常工作.此外,add_content方法与&符号一起正常工作.