我目前正在寻找使用touchXML库来阅读它,但它不能以预期的方式工作,因为它不支持流读取.
我想做点什么:
XmlReader pReader = XmlTextReader.Create(pPath); while (pReader.Read()){ switch (pReader.Localname){ case EXPEL_DEVICES: { //if ((pimportFlags & (int)ExportClass.Devices) != 0) //{ for (pReader.ReadToFollowing(LOCAL_name,nameSPACE_EXPORT); !pReader.EOF && pReader.Localname == @"name"; ) { if (!pReader.ReadToFollowing(DEVICE_ID,nameSPACE_EXPORT)) throw new AException(DEVICE_ID); Nsstring *value = pReader.ReadElementContentAsstring(); } } break; } }解决方法 在失去我自己的声望值50后,我终于使用了libxml2并将我的XMLStreamReader类作为以下内容,我希望我之前能够找到它:P.请注意,为了使用它,我们需要在我们的框架中包含libxml2.dylib,并在构建设置中将-lxml2添加到其他链接器标志中并在标头搜索路径中添加/usr/include / libxml2
头文件:
#import <Foundation/Foundation.h>#import <libxml/xmlreader.h>@interface XMLStreamReader : NSObject { xmlTextReaderPtr xmlReader;}@property (nonatomic,Readonly,assign) BOol eof;@property (nonatomic,retain) Nsstring *localname;@property (nonatomic,assign) xmlElementType nodeType;@property (nonatomic,assign) BOol read;@property (nonatomic,assign) BOol readElementContentAsBoolean;@property (nonatomic,retain) Nsstring *readElementContentAsstring;- (voID) close;- (ID) getAttribute:(Nsstring *) paramname;- (ID) initWithPath:(Nsstring *) path;@end
实施文件:
#import "XMLStreamReader.h"@implementation XMLStreamReader@dynamic eof;@dynamic localname;@dynamic nodeType;@dynamic read;@dynamic readElementContentAsBoolean;@dynamic readElementContentAsstring;- (voID) dealloc{ xmlFreeTextReader(xmlReader); [super dealloc];}/** * xmlTextReaderClose: * @reader: the xmlTextReaderPtr used * * This method releases any resources allocated by the current instance * changes the state to Closed and close any underlying input. * * Returns 0 or -1 in case of error */- (voID) close{ xmlTextReaderClose(xmlReader);}/** * @reader: the xmlTextReaderPtr used * @name: the qualifIEd name of the attribute. * * ProvIDes the value of the attribute with the specifIEd qualifIEd name. * * Returns a string containing the value of the specifIEd attribute,or NulL * in case of error. The string must be deallocated by the caller. */- (ID) getAttribute:(Nsstring *) paramname{ xmlChar *attribute = xmlTextReaderGetAttribute(xmlReader,(xmlChar *)[paramname UTF8String]); if(attribute != NulL){ Nsstring *rtString = [Nsstring stringWithUTF8String:(const char *)attribute]; free(attribute); return rtString; } return NulL;}/** * Checks if,the reader has reached to the end of file * 'EOF' is not used as it is already defined in stdio.h * as '#define EOF (-1)' */- (BOol) eof{ return xmlTextReaderReadState(xmlReader) == XML_TEXTREADER_MODE_EOF;}/** * Initializing the xml stream reader with some uri * or local path. */- (ID) initWithPath:(Nsstring *) path{ if(self = [super init]){ xmlReader = xmlNewTextReaderfilename([path UTF8String]); if(xmlReader == NulL) return nil; } return self;}/** * @reader: the xmlTextReaderPtr used * * The local name of the node. * * Returns the local name or NulL if not available,* if non NulL it need to be freed by the caller. */- (Nsstring *) localname{ xmlChar *lclname = xmlTextReaderLocalname(xmlReader); if(lclname != NulL){ Nsstring *rtString = [Nsstring stringWithUTF8String:(const char *)lclname]; free(lclname); return rtString; } return NulL;}- (xmlElementType) nodeType{ return xmlTextReaderNodeType(xmlReader);}/** * @reader: the xmlTextReaderPtr used * * Moves the position of the current instance to the next node in * the stream,exposing its propertIEs. * * Returns 1 if the node was read successfully,0 if there is no more * nodes to read,or -1 in case of error */- (BOol) read{ return xmlTextReaderRead(xmlReader);}/** * @reader: the xmlTextReaderPtr used * * Reads the contents of an element or a text node as a Boolean. * * Returns a string containing the contents of the Element or Text node,* or NulL if the reader is positioned on any other type of node. * The string must be deallocated by the caller. */- (voID) readElementContentAsBoolean{ return [[self readElementContentAsstring] boolValue];}/** * @reader: the xmlTextReaderPtr used * * Reads the contents of an element or a text node as a string. * * Returns a string containing the contents of the Element or Text node,* or NulL if the reader is positioned on any other type of node. * The string must be deallocated by the caller. */- (Nsstring *) readElementContentAsstring{ xmlChar *content = xmlTextReaderReadString(xmlReader); if(content != NulL){ Nsstring *rtString = [Nsstring stringWithUTF8String:(const char *)content]; free(content); return rtString; } return NulL;}/** * @reader: the xmlTextReaderPtr used * @localname: the local name of the attribute. * @namespaceURI: the namespace URI of the attribute. * * Moves the position of the current instance to the attribute with the * specifIEd local name and namespace URI. * * Returns 1 in case of success,-1 in case of error,0 if not found */- (int) readToFollowing:(Nsstring *) localname namespace:(Nsstring *) namespaceURI{ return xmlTextReaderMovetoAttributeNs(xmlReader,(xmlChar *)[localname UTF8String],(xmlChar *)[namespaceURI UTF8String]);}@end总结
以上是内存溢出为你收集整理的Objective C iPhone的XMLStreamReader?全部内容,希望文章能够帮你解决Objective C iPhone的XMLStreamReader?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)