Parsing multiple XML web file iphone - iphone

Let's say i have a xml file with a tag named which contains the number of fields i want to show in my tableView and in another xml file i have the information to be displayed in that tableView.
The question is : Should i create 2 different file in my project (xmlparse1.h and .m + xmlparse2.h and .m) or should i just put all my code in 1 (xmlparse.h + .m) and differenciate which file i am parsing at the moment with a bool or something like that in the code?
I am developing an iphone app on Xcode 4.3 mac os x 10.7.4 if this might change
EDIT: 1st file :
<MenuPrin>
<humidite>82,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</humidite>
<tempmoy>
189,124,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700
</tempmoy>
</MenuPrin>
2nd File :
<Instal>
<nbrField>2</nbrField>
</Instal>
So it looks like this. So, since nbrField is 2 I would take the 2 first value from tempMoy and humidite and show them in a tableView.
END OF EDIT

If how you're parsing is similar in both instances, to add two sets of files that do effectively the same thing would be extremely inefficient and considered bad practice. It makes a lot more sense to create a parser that can handle the two different files than to write two parsers that can only handle a specific file each.
To more specifically answer your question, I would determine which file you are parsing and behave accordingly, whether you do this with a bool or something else is up to you.
EDIT: Here is the idea that just popped into my head, so if for whatever reason this wont work for you(Like I said its been a while), or someone has a better idea, I'm all ears. You could still have a set of files(.h and .m) that contain the definition of your parser. Your parser could contain within it a two variables of type Object1 and Object2 which are built in such a way that they resemble the data structure that you need to store what you parse once for your first type of file, and a different definition for your second type of file. This way when parsing once you determine which file it is you are reading, it just changes which of these two objects you write into. There are also plenty of variations for how you could set this up, and I can also think of a few cases for what you might be trying to do where this might not work, but there is the idea regardless.
If you think that the two sets of files approach is better for the application you are trying to write and makes more sense to you, given what has been discussed in the comments, it isn't necessarily a bad idea.

In case if u want to create two table view in one view u need to create a single .h & .m file...If u want to create individual table view u need to create two .h & .m...
Try TBXML parser...that is the easiest way and less memory usage for xmlparsing...

Related

Structure in a single Swift file?

It might be basic and wrong but after understanding structures I can't understand where to practically put it.
Inside some class call it Main, I would like to encapsulate a set of variables for dimensions.
I know I can just do :
struct Dimensions{
var w:Int
var h:Int
}
class Main
{
//do things using the structure
}
But since i have a lot of variables and i want it clean , I would like to create a new Swift file and put it inside
So inside a file called Dimensions or else :
import Foundation
struct Dimensions{
var w:Int
var h:Int
}
then the structure is visible to anyone, without even using the Swift file name.
A few questions to ask :
It seems like a bad idea - why ?
How is it different from a Singeltone to share data between classes? (value type?)
What is the right place to put the structure outside the Main class to get some clear code ?
Should I make one file with many not related Structs ?
then the structure is visible to anyone
That is not true. Since your struct is not marked public, only code in your module can access it. Even if you write it in one single file, it is still accessible anywhere in your module.
without even using the Swift file name.
The reason why you are saying this might be because in other languages, you need to import a header file or something like that if you want to use something from another file (I'm not an expert in "other languages"). But Swift organises its code in units of modules, not files.
It seems like a bad idea - why ?
It is not a bad idea. Putting different types in different files is a good way to organise your code. When I go to Car.swift I wouldn't expect to see the class Game.
How is it different from a Singeltone to share data between classes? (value type?)
Here you are just writing things in different files. As far as the compiler is concerned, this is not much different from writing everything in a single file because Swift organises code in modules, not files. The Singleton pattern is something completely different. It is when you only have one shared instance of a type.
What is the right place to put the structure outside the Main class to get some clear code ?
In another file, because Main should really be in its own file.
Should I make one file with many not related Structs ?
No. That is a bad way of organising your code. When you want to find a particular struct, how do you know which file it is in?

Generating Swift files from templates

My goal is to create (find if exist) a tool which can produce swift files from templates.
For example, let’s say I need to create new ViewController with UITableView. It should be based on MVVM architecture with dependency injection. Let’s name this View “PersonsList”.
So, for this task I need to produce:
PersonListViewController
PersonListViewModel
PersonListViewModelProtocol
PersonCell
VM for cell and protocol for VM
Lots of files.
I want to say to my tool something like that
create tableview-template Person
and as a result get generated files. Files should contain empty implementation of each classes.
How should I do that? I am thinking about simple console app but I don’t know which language I should use. Maybe there is a better idea? Maybe there is a ready tool? Any help? :)
You could manually create the templates yourself and then write a short script (in Python / bash / swift etc) that goes through and replaces keywords with arguments you've passed in.

How to know if a Catpart is used in some product or not

I have hundreds of Catia V5 catparts and catproducts in a folder on hard disc. I want to know if a particular catpart is used in some catproduct or not. If it is not used in any product, I want to delete it and clean my hard disc. One way to do it is to open all catproducts one by one and check carefully they contain this model. This is cumbersome process and can lead to serious mistakes. Is there some automatic way to check it? If not, is it possible to write some macro for that purpose?
It is possible with a VBA script. If it's just Catpart file that your looking for in a product, then your script would work as follows
query your folder(s) for all catparts and catproducts.(use 2 dictionaries or arrays, one for each file type each)
Via a loop, Individually open and load each catproduct and essentially walk the tree and compare each child Catpart to your compiled list of catparts. If a match is found, movethe part to a new "white list"(dictionary or array)
Close the catproduct and check the next one.
Then, when all done, your original list(dictionary or array) will be your unused parts.
I'm not sure exactly how your models are built, but you may need to check for additional references/links in your catproducts (additional logic) before doing something like this.

what approach for adding custom methods to Core Data managed objects in separate files?

what approach for adding custom methods to Core Data managed objects in separate files? In particular the requirements would be I guess:
don't want to touch the XCode4 generated classes (i.e. so can regenerator them anytime and not have to redo changes within them)
can effectively add methods to the generated classes (assumption is the class names don't change)
Note - I'm aware of mogenerator but I'm not happy with it entirely at the moment noting https://github.com/rentzsch/mogenerator/issues/55
Would the simple and best answer be just Objective-C: Categories?
Fixing mogenerator would be the best answer :-).
mogenerator uses subclasses, so you could always do that, but categories would work as well.
I just tried... What do you think about a simple #include "included_dataStuff" and putting all your extra code into the "included_dataStuff" file.
There are two possibilities:
create a new ClassFile, delete the include "header.h", (delete the header.h), put the extra code there. It compiles but brings the two warnings: (which are understandable)
[WARN]warning: no rule to process file '$(PROJECT_DIR)/Classes/../included_dataStuff' of type text for architecture armv6
[WARN]warning: no rule to process file '$(PROJECT_DIR)/Classes/../included_dataStuff' of type text for architecture armv7
create a new "empty" file and put the extra code there. This does not produce any warnings.
The difference between 1 and 2 is that while the code formatting remains in the first alternatve (having to accept the 2 warnings) in the second all the code format is lost and its treated like normal text (but there is no warning)
I guess I would prefer the first. Of course, the only modification to the generated code file would be the #include statement.
What do you think about that?

How to create XML editor for iPhone?

I want to create a XML editor (form view type) for iphone. Can anyone suggest me how to proceed in this regard. I know how to parse an XML document but I am having trouble in editing the contents of the file dynamically. This editor should be such that, a new node can be added or a node can be deleted, it can also edit the values.
Please help...
In short you need to parse the document into a readable structure, finding a way to modify that structure, and write it back to XML.
Classes you are likely to need to write include MyXMLDocument, MyXMLNode, MyXMLElement and MyXMLTextNode, and MyXMLNode likely needs NSArray *children;, MyXMLNode *parent; and MyXMLDocument *document; as ivars.
You also probably need something akin to a -stringValue method; and an understanding of how the XML DOM usually works.