amarcadet / xmlreader Goto Github PK
View Code? Open in Web Editor NEWObjective-C XML reader based on NSXMLParser
Objective-C XML reader based on NSXMLParser
Hey,
great class you made here. I just want to notify it crashing when NSError **error equals NULL (which happens, quite often to me), and since you try to dereference the error in the init method (initWithError), it crashes. One way of solving this might be rewriting it as
if (error != NULL) self.errorPointer = *error;
what do you think?
Thanks,
G.
Please take a look at question i have here.
http://stackoverflow.com/questions/22577136/xmlreader-not-working-when-have-only-1-data
Basically, when I have one object, the format that you have is incorrect. For more info please visit stackoverflow link provided above.
I have an object c code connecting to a web server returning an xml.
after, I put the result into an NSDictionary:
self.xmlDictionary = [XMLReader dictionaryForXMLString:self.theXML options:XMLReaderOptionsProcessNamespaces error:&parseError];
NSLog(@"%@", self.xmlDictionary);
If my JSON returns more than 1 object my code counts the objects perfectly. But if my JSON returns only ONE object it miscounts.
My guess is the parenthesis are not inserted when only one value is returned.
Check my stack with complete code please:
http://stackoverflow.com/questions/33659623/objective-c-miscounting-array-with-json
Can I get result dictionary like on old version of XMLReader?
NSString *xmlString = @"<items><one id=\"1\">1</one><two><some>Test</some><some>Test2</some></two><three id=\"3\">3</three><four>4</four></items>";
Old XMLReader output
{
items = {
four = 4;
one = {
"@id" = 1;
text = 1;
};
three = {
"@id" = 3;
text = 3;
};
two = {
some = (
Test,
Test2
);
};
};
}
New XMLReader output:
{
items = {
four = {
text = 4;
};
one = {
id = 1;
text = 1;
};
three = {
id = 3;
text = 3;
};
two = {
some = (
{
text = Test;
},
{
text = Test2;
}
);
};
};
}
Hi,
Please add the license declaration to the top of each file.
Thanks,
Brian
I have an XML document, in the following format:
<?xml version="1.0" encoding="utf-8"?>
<vcread>
<bg_img id="32" title="背景(7)" x="0" y="0" width="320" height="480" src="333_07.jpg" tag="" seq="0" />
<item>
<text id="33" title="文本" x="19" y="309" width="284" height="166" type="char" content="ContentText"/>
</item>
</vcread>
Your code:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
// Update the parent dict with text info
NSMutableDictionary *dictInProgress = [self.dictionaryStack lastObject];
// Set the text property
if ([self.textInProgress length] > 0)
{
// trim after concatenating
NSString *trimmedString = [self.textInProgress stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[dictInProgress setObject:[trimmedString mutableCopy] forKey:kXMLReaderTextNodeKey];
// Reset the text
self.textInProgress = [[NSMutableString alloc] init];
}
// Pop the current dict
[self.dictionaryStack removeLastObject];
}
When the analysis is completed, item-> text has been nil, I debugged the code, find item-> text after the first, was reset to nil, so I modified the code and commit, please test,thank you
How can I edit and add custom tags to support SOAP?
Would you mind adding this to cocoapods? If you don't I'm going to end up forking and doing it myself
For the initWithError method declaration, this is given:
Which differs from the implementation:
This causes a warning in Xcode and I was wondering whether this could be fixed as my efforts to make them the same only led to more warnings.
First of all thanks for creating this great parser that helped me a lot.
Now i know that CData means you have to ignore while parsing, but in case i need to parse it then how can i do it?
I found one method in NSXMLParserDelegate and i implemented it as below. The problem is how to place the string parsed exactly where it belongs.
-(void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock
{
NSString *someString = [[NSString alloc] initWithData:CDATABlock encoding:NSUTF8StringEncoding];
// Build the text value
[self.textInProgress appendString:someString];
NSLog(@"-------CData String %@",someString);
}
XCode generates a "Pointer to non-const type" error on this line now:
NSError **errorPointer;
I'm not sure of the best workaround.
On the 'no-objc-arc' branch, seems to be a crash on parser release when other threads are using NSXMLParser
reference:
http://stackoverflow.com/a/687917/667834
Hi
Can you please confirm that original owner of this code Mr. Troy has given you distribution permission free of cost as license file is not mentioning about the same.
Our Open Source Scan team has been raised a concern for this and they want a formal confirmation for same for one of our commercial project.
Your timely reply really appreciate on this topic.
thanks Jatin
Is it possible to create key-value pair?
Rather then adding a node key "text".
Thanks in advance.
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.