Giter VIP home page Giter VIP logo

touchxml's Introduction

TouchXML

Introduction

TouchXML is a lightweight replacement for Cocoa's NSXML* cluster of classes. It is based on the commonly available Open Source libxml2 library.

License

This code is licensed under the 2-clause BSD license ("Simplified BSD License" or "FreeBSD License") license. The license is reproduced below:

Copyright 2011 Jonathan Wight. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY JONATHAN WIGHT ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JONATHAN WIGHT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of Jonathan Wight.

Automatic Reference Counting (ARC)

The "master" branch of TouchJSON does NOT use Automatic Reference Counting (ARC).

There is a branch that does use ARC - this is found at "features/ARC".

Most new development occurs on the ARC branch. At some point the non-ARC branch will put into maintenance mode and the ARC branch will become the primary branch.

Goals

The goal is to create a lightweight NSXML* style XML api that can used in environments without NSXML* (e.g. iPhone).

  • XML read only. The aim is to make a lite API for reading XML. I'm assuming most applications will only need to read XML and wont need to generate it (AJAX applications tend to receive XML data but transmit data via URL or HTTP form-encoding). Please let me know if your application needs XML write support.

  • Lightweight. Rarely used NSXML* functionality should not be implemented.

See http://github.com/TouchCode/TouchXML for more.

touchxml's People

Contributors

5minpause avatar adambuckley avatar catflight avatar derrh avatar greggjaskiewicz avatar itruf avatar jawngee avatar jcmontiel avatar jpedroso avatar muccy avatar ntamas avatar pylebecq avatar samuelchen avatar schwa avatar sophistifunk avatar tbrannam avatar volodg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

touchxml's Issues

CXMLDocument.m broken if using Tidy

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

Can't parse root note with attributes?

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.

Missing include of HTMLparser

The features/ARC branch has an incorrect include.

CXHTMLDocument.m:42

include < libxml/htmlparser.h >

should be

include < libxml/HTMLparser.h >

Crash in CXMLNode_PrivateExtensions

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

Add TouchXML.xcodeproj/xcuserdata/* to the .gitignore

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.

No parse errors?

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...

Readme File

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.

[CXMLNode name] should return nil for some node types

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.

EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x2c in CXMLElement

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.

Include fixes

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

Outdated licence in README.markdown

README.markdown still states that TouchXML is released under the modified BSD licence, but LICENSE.txt was changed from modified BSD to MIT.

Add a new tag for Cocoapods

@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.

Parse error handling

How to fetch parse errors? If I set a NSError object, it's every time nil. How does it work?

Private API conflict

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.

CXMLDocument initWithXMLString crashes with empty XML string

If CXmlDocument initWithXMLString given a nil string will crash on line 76.

  • xmlParseDoc returns NULL
  • xmlGetLastError returns nil
  • line 76 does not test for this case, causing a nil dereference crash
    ** similar line 140 does test for this case, avoiding the crash

[CXMLNode children] crash caused by adding nil object to NSMutableArray

  • (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

[CXMLNode dealloc] EXC_BAD_ACCESS

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;
    }
    //
    }

Support for other encodings than UTF8

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);
             }

If the node content is not valid UTF-8, parser crashes

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;
}

Encoding in CTidy

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?

Add version number

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.