开发者

Porting XML parsing from Java to Objective C

开发者 https://www.devze.com 2023-01-27 18:41 出处:网络
I am trying to port code written in Java to Objective C (for iPhone), but I\'m kind of confused about a few lines of my code (mentioned below). How should I port this efficiently?

I am trying to port code written in Java to Objective C (for iPhone), but I'm kind of confused about a few lines of my code (mentioned below). How should I port this efficiently?

Namespace nmgrhistory=Namespace.getNamespace("history", "http://www.mywebsite.com/History.xsd");
        pEventEl.addContent(new Element("History",nmgrhistory));
        Namespace nmgrState=Namespace.getNamespace("state", "http://www.mywebsite开发者_开发技巧.com/State.xsd");
        pEventEl.addContent(new Element("State",nmgrState));

        Iterator<Element> eld=(Iterator<Element>) pEventEl.getChild(
                pEventEl.getName() == "event"?  "./history:history/state:state" : "./state:state",pEventEl.getNamespace());

I'm not very sure about the replacements for the classes Namespace, Iterator and Element.

Anybody having idea or having done this before, please enlighten me.


Ok... So although these are not the actual replacements ... But basically what u need for parsing XML in Objecive - C is "NSXMLParser"

so u can say that NSXMLParser is the replacement for Namespace

And for "Iterator" NSXMLParserDelegate has a method named:-

– parser:didStartElement:namespaceURI:qualifiedName:attributes:

OR

– parser:foundCharacters:


I don't know java, but the url's your are pointing at are .xsd files which are xml definition files. XML parsing on iOS is somewhat limited out of the box: NSXMLParser.

I strongly recommend one of the bazillion open source XML parsers. They're much more user friendly.


Well thanks to all for making the efforts to answer, but I got a nice library TouchXML that solves the purpose.

0

精彩评论

暂无评论...
验证码 换一张
取 消