UPDATE2我想我找到了泄漏的真正来源。我有一些业务对象具有我忘记发布的字符串属性。这些字符串属性是从我的自定义 xlm 节点对象复制而来的,在此处创建 (KGYXMLNode) 我不明白为什么在这里报告泄漏而不是我的自定义类。我的 NSString 属性是copy和不是retain.
更新:我认为这是 Instruments 中的错误或其他东西,或者它不再神奇地泄漏,但是由于 xcode 4 它没有显示此泄漏。
您好,根据仪器,我在以下代码中有泄漏。我已经围绕某些 libxml 函数构建了一个 Objective-c 包装器,以便能够使用 xpath 解析 xml 文档,并且在这种方法中,我为我的自定义节点对象设置了innerText。
-(void) SetInnerTextForNode: (xmlNodePtr) node : (KGYXMLNode *) obcNode
{
if ((node) && (node->children))
{
for (xmlNodePtr pnode = node->children; pnode != NULL; pnode = pnode->next)
{
if (pnode->type == XML_TEXT_NODE)
{
xmlChar *content = pnode->content;
NSString *innerText = [[NSString alloc] initWithUTF8String: (char *)content];
NSString *trimmedText = [innerText stringByTrimmingCharactersInSet: trimCharSet];
if (trimmedText.length > 0) …Run Code Online (Sandbox Code Playgroud) 我在xcode工作区中有2个项目.一个是静态库,另一个是静态库.
在静态库中,我添加了GDataXMLNode.h和GDataXMLNode.m文件,我在主项目中使用它们.GDataXMLNode.h是一个公共文件,因此它在主项目中可见.我还将两个项目的目标与libxml2.dylib相关联.我还在头部搜索路径和用户头搜索路径中包含位置/ usr/include/libxml2.
虽然这些,我得到Apple Mach-O Librarian错误:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: can't locate file for: -lxml2
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: -lxml2 is not an object file (not allowed in a library)
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/libxml2.dylib is a dynamic library, not added to the static library
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/libxml2.dylib is a dynamic library, not added to the static library
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/libz.dylib is a dynamic library, not added to the static library
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool: file: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/libz.dylib is a dynamic library, not added to the static library
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool failed …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个函数,它将在xml文件中找到具有指定名称的节点.问题是该函数永远不会找到指定的节点.
xmlNodePtr findNodeByName(xmlNodePtr rootnode, const xmlChar * nodename)
{
xmlNodePtr node = rootnode;
if(node == NULL){
log_err("Document is empty!");
return NULL;
}
while(node != NULL){
if(!xmlStrcmp(node->name, nodename)){
return node;
}
else if(node->children != NULL){
node = node->children;
xmlNodePtr intNode = findNodeByName(node, nodename);
if(intNode != NULL){
return intNode;
}
}
node = node->next;
}
return NULL;
}
Run Code Online (Sandbox Code Playgroud)
我可以在调试器中看到函数确实深入到子节点但仍然返回NULL.
提前致谢.
WinXP在不同机器上的IDE.LibXML2.dll从2010年到2012年,两台机器的版本/日期各不相同.
我libxml2.pas从SourceForge(2.7.3)安装我在XE2上创建了3个应用程序,一个控制台和一个VCL表单,在D2007上创建了一个VCL表单.
如果我在Libxml2.dll我的app运行中没有引用一个函数,如果我引用一个函数,例如Doc:=xxmlParseFile(xnldocptr)应用程序在启动时崩溃了InitUnits.
program Project25;
uses
Forms,
Unit26 in 'Unit26.pas' {Form26};
{$R *.res}
begin<---------- Access violation here
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm26, Form26);
Application.Run;
end.
Run Code Online (Sandbox Code Playgroud)

// Main Firm使用Libxml2;
{$R *.dfm}
procedure TForm26.FormCreate(Sender: TObject); var Doc: xmlDocPtr;
begin
Doc:=xmlParseFile('c:\a.xml');
xmlFreeDoc(Doc);
end
Run Code Online (Sandbox Code Playgroud)
我可以看到已加载模块LibXML2.
我做的事情愚蠢还是缺少某些东西?
在下面的代码中,我试图解析SVG文件并删除其中的所有文本节点.但是,它不起作用(代码永远不会进入fornop for findnodes).我究竟做错了什么?我试过XPath和LibXML版本的代码,但没有一个工作.他们解析并转储文件很好,但findnodes什么都不匹配.
#!/usr/bin/perl
use strict;
use warnings;
use XML::XPath;
use XML::XPath::XMLParser;
my $num_args=$#ARGV+1;
if($num_args != 1) { print "Usage: $0 <filename>\n"; exit(1); }
my $file=$ARGV[0];
my $doc = XML::XPath->new(filename => $file);
foreach my $dead ($doc->findnodes('/svg/text')) {
print "Found Text Node\n";
$dead->unbindNode;
}
Run Code Online (Sandbox Code Playgroud)
从SVG文件的几行开始:
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
width="675"
height="832.5"
id="svg2"
xml:space="preserve"><metadata
id="metadata8"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
id="defs6" /><g
transform="matrix(1.25,0,0,-1.25,0,832.5)"
id="g10"><path
d="m 54,608.663 450,0 M 54,129.052 l 450,0"
inkscape:connector-curvature="0"
id="path12"
style="fill:none;stroke:#231f20;stroke-width:0.5;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none" /><text
transform="matrix(1,0,0,-1,229.0848,615.9133)"
id="text14"><tspan
Run Code Online (Sandbox Code Playgroud)
@
我使用libXML的SAX接口在C++中编写XML解析器应用程序.
<abc value="xyz "pqr""/>
Run Code Online (Sandbox Code Playgroud)
我该如何解析这个属性?
我试过用
void startElementNsSAX2Func(void * ctx, const xmlChar *localname, const xmlChar *prefix, const xmlChar *URI, int nb_namespaces, const xmlChar ** namespaces, int nb_attributes, int nb_defaulted, const xmlChar ** attributes)
Run Code Online (Sandbox Code Playgroud)
,递增属性参数(并检查" 以指示属性值的结束)".
它适用于除*"*属性值之外的所有属性.
解析这些属性值的正确方法是什么?
谢谢
我正在使用Ubuntu Server 14.04.我需要使用./configure --enable-unicode = ucs4选项来创建我的新django项目python.我用ucs4重新安装了python.
现在,当我试图运行scrapy spider时,我收到如下错误:
ImportError: /usr/local/lib/python2.7/site-packages/lxml-3.4.2-py2.7-linux-x86_64.egg/lxml/etree.so: undefined symbol: PyUnicodeUCS2_DecodeLatin1
Run Code Online (Sandbox Code Playgroud)
然后我试图再次重新安装python但出现错误:
Compiling /usr/local/lib/python2.7/zipfile.py ...
make: *** [libinstall] Error 1
Run Code Online (Sandbox Code Playgroud)
然后我试图重新安装libxml,但也有错误:
/usr/bin/ld: /usr/local/lib/python2.7/config/libpython2.7.a(abstract.o): relocation R_X86_64_32S against `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/python2.7/config/libpython2.7.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
Scrapy重新安装没有帮助.
请帮忙!
当我
$ brew install libxml2
Run Code Online (Sandbox Code Playgroud)
我明白了:
警告:libxml2是一个仅限keg,另一个版本链接到opt.
使用brew install --force,如果你想安装此版本
那么,这里有什么问题吗?或者只是一个较新的版本出来,我可以安装更新的版本?
我有这个警告:
brew install libiconv
Run Code Online (Sandbox Code Playgroud)
太.
据说是因为libxml2unsigned char用作存储,方便字符集之间的编码/解码----在读取/创建xml节点名称,内容,文本时,强制用户在代码中到处写“BAD_CAST”是不是很丑陋节点等
有没有办法避免到处写这样的“BAD_CAST”?设计真的太差了。
我想使用 XMLReader 解析一个 XML 文档。我有一个带有所有常量的案例开关。但是,如果标签是自关闭的 XMLReader 只触发 ELEMENT,而不是像预期的那样触发 ELEMENT 和 END_ELEMENT。
通过类属性 $isEmptyElement 进行检测也不起作用,因为该标记具有属性。
因此我的问题是:如何在 PHP 中使用 XMLReader 检测自关闭的 XML 标记?
相关但没有解决方案: XmlReader - 自关闭元素不会触发 EndElement 事件?
示例节点:
<mynode name="somenamestring" code="intstring" option="intstring3"/>
Run Code Online (Sandbox Code Playgroud)
我的代码:
$xmlReader->open($url,NULL);
$xmlWriter = new XMLWriter();
$xmlWriter->openMemory();
$xmlWriter->startDocument('1.0', 'UTF-8');
$xmlWriter->setIndent(true);
$xmlWriter->setIndentString(' ');
while ($xmlReader->read()) {
switch ($xmlReader->nodeType) {
case 1: #element
$xmlWriter->startElement($xmlReader->name);
if ($xmlReader->hasAttributes) {
while ($xmlReader->moveToNextAttribute()) {
$xmlWriter->writeAttribute($xmlReader->name,$xmlReader->value);
}
}
if ($xmlReader->isEmptyElement) {
$xmlWriter->endElement();
}
break;
case 3: #text
$xmlWriter->text($xmlReader->value);
break;
case 4: #cdata
$xmlWriter->writeCData($xmlReader->value);
break; …Run Code Online (Sandbox Code Playgroud) libxml2 ×10
c ×2
iphone ×2
linux ×2
objective-c ×2
c++ ×1
casting ×1
delphi ×1
homebrew ×1
installation ×1
instruments ×1
ios ×1
memory-leaks ×1
parsing ×1
perl ×1
php ×1
python ×1
sax ×1
saxparser ×1
svg ×1
ubuntu ×1
xml ×1
xml-parsing ×1
xmlreader ×1