touchcode / touchxml Goto Github PK
View Code? Open in Web Editor NEWiOS port of NSXMLDocument
iOS port of NSXMLDocument
Hello,
There are some small problems with the readme file. First: rename it to README.md, because it will be parsed into HTML by github.
The other thing is the link: http://github.com/schwa/TouchXML, i Don't know what's the original target, but the link is broken.
The <tree.h>
reference in CXMLDocument.h should be <libxml/tree.h>
Xcode was also complaining about <CXMLDocument.h>
to be "CXMLDocument.h"
From cf1f904f50fc94cb1ce91a20b0f85fa9e5d9fb4f Mon Sep 17 00:00:00 2001
Date: Mon, 21 Apr 2014 18:58:23 -0700
Subject: [PATCH] fix includes
---
Source/CXMLDocument.h | 2 +-
Source/Creation/CXMLDocument_CreationExtensions.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/Source/CXMLDocument.h b/Source/CXMLDocument.h
index 4eea3bc..2f32e13 100644
--- a/Source/CXMLDocument.h
+++ b/Source/CXMLDocument.h
@@ -31,7 +31,7 @@
#import "CXMLNode.h"
-#include <tree.h>
+#include <libxml/tree.h>
enum {
CXMLDocumentTidyHTML = 1 << 9, // Based on NSXMLDocumentTidyHTML
diff --git a/Source/Creation/CXMLDocument_CreationExtensions.h b/Source/Creation/CXMLDocument_CreationExtensions.h
index 07ea16f..499e37c 100644
--- a/Source/Creation/CXMLDocument_CreationExtensions.h
+++ b/Source/Creation/CXMLDocument_CreationExtensions.h
@@ -29,7 +29,7 @@
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of toxicsoftware.com.
-#import <CXMLDocument.h>
+#import "CXMLDocument.h"
@interface CXMLDocument (CXMLDocument_CreationExtensions)
--
1.9.1
Seeing a bunch of random crashes via Crashlytics in the ARC branch:
CXMLNode_PrivateExtensions.m line 76
+[CXMLNode(CXMLNode_PrivateExtensions) nodeWithLibXMLNode:freeOnDealloc:]
I think it's crashing as a result of the NSAssert
-[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 90
Here is little patch to support other encodings than UTF8 for the features/ARC branch
@@ -98,7 +98,7 @@
- (id)initWithData:(NSData *)inData options:(NSUInteger)inOptions error:(NSError **)outError
{
- return [self initWithData:inData encoding:NSUTF8StringEncoding options:inOptions error:outError];
+ return [self initWithData:inData encoding:0 options:inOptions error:outError];
}
- (id)initWithData:(NSData *)inData encoding:(NSStringEncoding)encoding options:(NSUInteger)inOptions error:(NSError **)outError
@@ -126,7 +126,7 @@
{
CFStringEncoding cfenc = CFStringConvertNSStringEncodingToEncoding(encoding);
CFStringRef cfencstr = CFStringConvertEncodingToIANACharSetName(cfenc);
- const char *enc = CFStringGetCStringPtr(cfencstr, 0);
+ const char *enc = cfencstr != NULL ? CFStringGetCStringPtr(cfencstr, 0) : NULL;
theDoc = xmlReadMemory([inData bytes], [inData length], NULL, enc, XML_PARSE_RECOVER | XML_PARSE_NOWARNING);
}
README.markdown still states that TouchXML is released under the modified BSD licence, but LICENSE.txt was changed from modified BSD to MIT.
Hi! This is not really a bug...
I'm using this app as a submodule of a bigger project, and i'm having problems when I do the commits, because xcode writes on this directory each time that i make a change in my project
Thanks.
My app was just rejected from Apple with a Private API Conflict in the "elementWithName:" method used in three files: CXMLNode_CreationExtensions.h, CXMLNode_CreationExtensions.m and CXMLElement_ElementTreeExtensions.m. This method will need to be renamed within TouchXML in order for apps using this library to be approved.
Issue is detailed in this Open Radar ticket and appears to still be an issue:
Get this warning building with Xcode 4 with a Mac / Cocoa app
@schwa Would you mind bumping the version Cocoapods can see? (ie. add a new tagged commit)
The 0.1 tag is 8 months old and doesn't include the various "fixes" for node unlinking.
I was getting strange results when parsing an .acbf file, so I started whittling it down until it finally read correctly. Here's the file that won't read correctly with TouchXML:
This results in an empty array:
CXMLDocument* doc = [[CXMLDocument alloc] initWithContentsOfURL:url options:0 error:&err];
NSLog(@"%@", [doc.rootElement nodesForXPath:@"/ACBF" error:&err]);
Removing the xmlns attribute allows it to parse correctly.
It works correctly WITH the xmlns attribute when using NSXMLDocument instead of CXMLDocument.
I just switched over to ARC and I am on the feature/ARC branch. I receive an EXC_BAD_ACCESS once I am done parsing. The parsing happens inside an @autoreleasepool.
(void)dealloc
{
if (_node)
{
if (_node->_private == (__bridge void )self) // * EXC_BAD_ACCESS **
_node->_private = NULL;
if (_freeNodeOnRelease)
{
xmlFreeNode(_node);
}
_node = NULL;
}
//
}
The features/ARC branch has an incorrect include.
CXHTMLDocument.m:42
should be
There could be a more robust handling of the case the content of the XML node is not a valid UTF-8.
I suggest fixing the issue by null checking the value in CXMLNode::stringValue.
- (NSString *)stringValue
{
NSAssert(_node != NULL, @"CXMLNode does not have attached libxml2 _node.");
if (_node->type == XML_TEXT_NODE || _node->type == XML_CDATA_SECTION_NODE)
return [NSString stringWithUTF8String:(const char *)_node->content];
if (_node->type == XML_ATTRIBUTE_NODE)
return [NSString stringWithUTF8String:(const char *)_node->children->content];
NSMutableString *theStringValue = [[[NSMutableString alloc] init] autorelease];
for (CXMLNode *child in [self children])
{
+ if (nil != [child stringValue]) {
[theStringValue appendString:[child stringValue]];
+ }
}
return theStringValue;
}
tidyData:inData inputFormat:TidyFormat_HTML outputFormat:TidyFormat_XHTML diagnostics:NULL error:
Should be
inData = [[CTidy tidy] tidyData:inData inputFormat:TidyFormat_HTML outputFormat:TidyFormat_XHTML encoding:NULL diagnostics:NULL error:&theError];
CTidy's method includes encoding tidyData:inputFormat:outputFormat:encoding:diagnostics:error
If CXmlDocument initWithXMLString given a nil string will crash on line 76.
Make features/ARC
the Primary branch, and create a PODSPEC v 1.0.
Last changes in main
(non ARC) and features/ARC
were authored on Mar 30, 2014.
This is a token of stability.
Unable to run gmalloc when releasing CXMLDocument. error in the [CXMLNode dealloc] method
When using CTidy to tidy up HTML or XHTML, it tends to throw in a lot of incorrect characters - especially "ร". This can be fixed by specifying the encoding of the HTML input in the "tidy" method - e.g.:
theResultCode = tidySetInCharEncoding(theTidyDocument, "utf8");
CTidy might benefit from allowing the user to specify the encoding of the input?
I'm creating a podspec file for CocoaPods so it will be even easier to use TouchXML. To create a good spec, I want to specify a version number. Could you add a version number and a git tag for that version number?
(NSArray *)children
{
NSAssert(_node != NULL, @"CXMLNode does not have attached libxml2 _node.");
NSMutableArray *theChildren = [NSMutableArray array];
if (_node->type != CXMLAttributeKind) // NSXML Attribs don't have children.
{
xmlNodePtr theCurrentNode = _node->children;
while (theCurrentNode != NULL)
{
CXMLNode *theNode = [CXMLNode nodeWithLibXMLNode:theCurrentNode freeOnDealloc:NO];
[theChildren addObject:theNode];// CRASH
theCurrentNode = theCurrentNode->next;
}
}
return(theChildren);
}
I suggest a check on theNode so if it is nil, it doesn't try add the object to the NSMutableArray
See https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLNode_Class/Reference/Reference.html for documentation of the name method.
In particular, the name method should only return a non-nil value for elements, attributes, namespaces, processing instructions, and DTD-declaration nodes - according to Apple's documentation.
Am I correct in thinking that TouchXML should attempt to mimic this behaviour? Currently TouchXML returns names for text nodes ("text"), in particular, which is confusing some third party code I'm using which depends upon the specified behaviour of name as above.
I would be happy to submit a pull-request if you agree this is an issue.
I'm parsing a document (https://gist.github.com/1661753) with:
NSError *error; CXMLDocument *document = [[CXMLDocument alloc] initWithData:data options:0 error:&error];
or with:
NSError *error; CXMLDocument *document = [[CXMLDocument alloc] initWithContentsOfURL:[NSURL fileURLWithPath:configPath] encoding:NSUTF8StringEncoding options:0 error:&error];
And in both cases i get the following on the console:
Entity: line 5: parser error : Opening and ending tag mismatch: tab line 3 and app </app> ^ Entity: line 5: parser error : Premature end of data in tag app line 2 </app>
but error is still equal to 0...
We have used TouchXML in our app to parse XMLs coming from our backend.
In some circumstances app gives EXC BAD ACCESS in the following method:[CXMLElement attributeforName:]
Is there anyone who experienced this? I did not debugged it in detail yet but I think it is happening in xmlStrcmp(theLocalName, theCurrentNode->name) part.
More specifically in theCurrentNode->name.
while (theCurrentNode != NULL)
{
if (xmlStrcmp(theLocalName, theCurrentNode->name) == 0)
{
if (thePrefix == NULL || (theCurrentNode->ns
&& theCurrentNode->ns->prefix
&& xmlStrcmp(thePrefix, theCurrentNode->ns->prefix) == 0))
{
CXMLNode *theAttribute = [CXMLNode nodeWithLibXMLNode:(xmlNodePtr)theCurrentNode freeOnDealloc:NO];
return(theAttribute);
}
}
theCurrentNode = theCurrentNode->next;
}
return(NULL);
It is very hard to debug this because it happens randomly and it is not happening in all nodes. So let me know if you experienced this and there is a way to prevent this.
Thanks for your help in advance.
How to fetch parse errors? If I set a NSError object, it's every time nil. How does it work?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.