Possible to validate xml against xsd using Objc/iPhone code at runtime - iphone

I have xml files that I read in at runtime, is it possible to validate the xml against an xsd file at runtime using Obj C?? This can be done in java and c#.. But i need do it run time in my iphone app.

I don't think you can do this using Obj C on iOS. I think you'll need to use libxml2.
Here's an example of a simple C program that validates XML against XSD.
Here are instructions on adding libxml2 to an XCode project.

CodeSynthesis XSD/e
should support iPhone (inside the Mac package)
Edit #1: Setup instruction
To build the XSD/e runtime library (libxsde.a), perform the following steps:
Unpack the pre-compiled XSD/e package for Mac OS X.
Start a new terminal window and run the following commands:
cd xsde-3.2.0-i686-macosx
cp etc/ios/config-xcode.make config/config.make
Don't close the terminal.
Edit config/config.make and adjust the XSD/e configuration to suit your
requirements.
In the terminal, execute:
cd libxsde
make
If the make command is not found, try /Developer/usr/bin/make (or your
alternative XCode installation directory).
Start XCode and perform the following steps:
5.1 Select "File"->"New Project"
5.2 In the opened dialog select "iOS Library"->"Cocoa Touch Static
Library". Click "Choose...".
5.3 In the next dialog type libxsde in the "Save As" field and navigate
to the xsde-3.2.0-i686-macosx directory. Click "Save".
5.4 Next you should see a warning dialog saying that the libxsde directory
already exists. This is expected so click "Replace".
5.5 In the project window in the "Groups & Files" list select "Other
Sources" group, then select "Project"->"Add to Project...".
5.6 In the opened dialog navigate to the xsde-3.2.0-i686-macosx/libxsde directory and
select the src directory. Click "Add".
5.7 In the next dialog leave the default settings and click "Add". Now
you should see multiple source files (.cxx and .c) listed in the
"Other Sources" group.
5.8 Next select "Project"->"Edit Project Settings", "Build" tab. In the
"Configurations" drop-down list select "All Configurations".
5.9 Scroll down to the "Search Paths" section and add . (dot) to the
"Header Search Paths" field.
5.10 Scroll down to the "GCC 4.2 - Language" section and add the
-fvisibility=hidden flag to the "Other C Flags" field as well
as the -fvisibility=hidden and -fvisibility-inlines-hidden flags
to the "Other C++ Flags" field. If you set any extra C/C++ flags
in your application's project, you may also want to add them here.
5.11 Build the project for all the desired configurations (for example,
Debug/Release, Device/Simulator, ARMv6/ARMv7, etc).
In the terminal window create "fat" libraries by running the following
commands (which may need to be adjusted depending on the configurations
that you have built):
cd build
lipo -output libxsde.a -create Release-iphonesimulator/liblibxsde.a Release-iphoneos/liblibxsde.a
lipo -output libxsde-d.a -create Debug-iphonesimulator/liblibxsde.a Debug-iphoneos/liblibxsde.a
If at some point you need to change the XSD/e configuration then it is best
to start from scratch (step 1 above) since the set of files that is added
to the XCode project may vary from configuration to configuration.
Once the runtime library is built, to integrate XSD/e into your application
perform the following steps:
Compile your schemas to C++ with the XSD/e compiler (xsde-3.2.0-i686-macosx/bin/xsde)
and add the resulting generated C++ files to your project.
To link your application to the XSD/e runtime library (libxsde), perform
the following steps in your project:
2.1 In the "Targets" group, double-click on your application to open the
"Info" dialog.
2.2 Select the "General" tab and click on the Plus (+) button to add the
library.
2.3 In the opened dialog click the "Add Other..." button and add either
the libxsde.a or libxsde-d.a (debug) fat library created above.
To add the XSD/e runtime headers to your application's search paths,
perform the following steps in your project:
3.1 Select "Project"->"Edit Project Settings", "Build" tab. In the
"Configurations" drop-down list select "All Configurations".
3.2 Scroll down to the "Search Paths" section and add the path to the
xsde-3.2.0-i686-macosx/libxsde directory to the "Header Search Paths" field.
3.3 Build the application.

there are no sdks for this in the objC Api for iOS. To do this you have to drop down to using libxml's C APIs directly.
you load the xml (e.g. xmlReadMemory)
then for XSD you'd use xmlSchemaValidateDoc
or you can use the following wrapper class [disclaimer: I am the author]:
DDXMLValidator (part of my helpers # https://github.com/Daij-Djan/DDUtils/)
//validate
NSError *error = nil;
NSURL *schemaURL = [[NSBundle mainBundle] URLForResource:#"XMLSchema" withExtension:#"xsd"];
if(![[SNXMLValidator sharedInstace] validateXMLData:xmlData withSchema:SNXMLValidatorSchemaTypeXSD schemaFile:schemaURL error:&error]) {
DebugLog(#"Failed to validate data: %#", error);
}
the class can do DTD, XSD, RelaxNG (it just wraps libxml2)

Related

Is 'all:' is default in Eclipse makefile?

I have c++ makefile project in Eclipse. Makefile contains lines:
executable:
$(COMPILER) $(CFLAGS) aaa.cpp -o aaa.o
$(COMPILER) aaa.o -o aaa.exe -ldl
Eclipse is not happy with executable and shows error;
make all
make: *** No rule to make target 'all'. Stop.
How to tell Eclipse to use executable instead all?
While I don't use Eclipse and couldn't tell you how to change the default build target, it may be worthwhile to have a target all since it's a pretty common thing to have.
Just specify all as the first target:
all: executable
As the first target it's also be the default target when no target is specified on the command line. Since the rule has no commands, all it does is depend on executable being built, effectively becoming an alias. To be extra safe, add
.PHONY: all
somewhere (or to existing .PHONY lines if you already have them) so that the existence of a file all won't prevent building.
Open the Makefile in the editor.
Select "Outline View" (or open it using Window -> Show View -> Outline).
In the outline view right click on "executable" and select "Add Build Target" from the drop down menu.
Go to "Build Targets" view (or open it using Window -> Show View -> Build Targets).
The target should appear in that window under the project folder name. If it is not there (quirk) select and deselect the "Hide Empty Folders" icon in the top right of that window.
Then just double click on that entry to make that target. Do the same for other targets (clean etc...).

How to link to cublas library in eclipse Nsight?

I am using Nvidia's example code for simpleCUBLAS. The example comes with a Makefile, or I can compile it like this:
g++ -m32 -I/usr/local/cuda/include -I. -o simpleCUBLAS.o -c simpleCUBLAS.cc
g++ -m32 -o simpleCUBLAS simpleCUBLAS.o -L/usr/local/cuda/lib -l cudart -l cublas
(the files included by the "-I." are cuda_runtime.h helper_cuda.h helper_string.h)
This compiles and runs just fine.
However, I would like to make this using Eclipse's Nsight editor for CUDA.
My Question is:
How to I add these options to Eclipse (the -L/usr/local/cuda/lib -l cudart -l cublas, & the -I.) Nsight?
Other details:
Am using Linux.
I've seen some info elsewhere for Eclipse & c/c++ Project, BUT here I am using cuda c/c++ Project.
Thanks.
I don't think any of this is specific to Nsight Eclipse Edition. What you are trying to do are standard operations for any C/C++ project built using Eclipse. Nsight EE doesn't change these steps in any major way. You can get help easily enough on these topics using the built-in Eclipse help in Nsight EE. For example:
open help (select help...help contents)
in the search box type "add library"
click on the first item returned in the help search pane
All of your questions (adding library paths, adding libraries, adding include paths) have to do with the Project Properties. We can access these properties directly by:
Open the project in Nsight EE
In the project pane on the left, right-click on the project whose properties you wish to inspect/modify, then select "Properties" from the pop-up menu (the last item in the menu)
The project properties pane is now open.
Click on the triangle next to "General" in the properties dialog. This will open the "General" sub-menu.
Under General, click on "Paths and Symbols" The generic Eclipse help would have taken you this far.
Now click on "CUDA C" (Yes this is the one step that is different.)
The tabs across the top now include selections for things like "Includes", Libraries", "Library Paths" etc. By selecting any one of these tabs, you can add or modify the appropriate entries.
So as one example, let's add the cublas library. Select the "Libraries" tab.
Now click the "Add" button
Enter the name of the library. It is cublas, not lcublas, and not -lcublas
now click "OK", "Apply" and exit out of the properties, build your project, and confirm that -lcublas has been added to the build command

Getting XCode to include, compile and link existing (C++) codebase in XCode 4.3(.1)

I'm trying to 'import' my existing C++ codebase into my XCode iOS project.
Problem is, xCode won't compile (and therefore not link) my code.
This is what I've done so far:
File > Add files to "Project". I don't tick 'Copy files' since it's a shared codebase for multiple platforms and multiple copies of source code is not an option.
I've added appropriate path to the "Header Search Path" project settings. Including header files works, I can #include "stuff.h" from my Objective-C++ (.mm) file.
However, I can't find any way of actually telling XCode to compile the .cpp files?
A few points:
I'm not looking for a way to pre compile it into a library and linking that way
The project is a standard iOS Objective-C project. The C++ code is called from it (that's not a problem)
Update
I've added the codebase directory to the target's "Compile Sources". I actually have to click "Add other..." in the dialog that pops up, since I can't select the directory reference to my codebase.
When I add it, XCode asks me if I want to "Create external build system project". I leave it ticked and the two fields with the default values "/usr/bin/make" and "$(ACTION)". However, my codebase doesn't get compiled during the build. Do I have to write my own Makefile ?
If I don't select "Create external build system project" then a directory reference is created under the target, but not compiled during the build and a warning is emitted:
warning: no rule to process file '$(PROJECT_DIR)/../codebase'
of type folder for architecture i386
Even if you don't check Copy Files you have to check Add to Targets when adding the files to the project.
If you forgot to do that, you can select the target, go to the Build Phases tab and add the files to Compile Sources.
If you go to your Targets -> Build Phases -> Compile Sources -> "+" -> "Add Others" -> (select your external source folder) -> Select: Create Group for any added folders -> Unchecked: Copy items into destination.
Now your folder will be in XCode, mimic the structure. If you add source files to that folder in XCode the source files will be added to your external source directory just fine. So the ease of using multiple IDEs and having to manage source linkage is solved.
The catch. You still have to manually add files into the "Compile Sources" area. This is rather simple. Just click and drag your source files from the group directory in XCode right into the Compile Sources window. So there is an extra step when you add a source file now. Forgetting to add them to the Compile Sources window will yield unresolved symbols compile errors.

How to integrate RestKit Framework (restkit.org) with xCode 4?

I followed the instructions on the github page but something is wrong (most certainly is me: P) but, Do you know about any good tutorial for integrate / use in Xcode4 RestKit?
Thanks!
Download the latest version from this Link http://restkit.org/
and extract the zip folder and you will find a ReadMe.md file which explains you steps to install for Xcode 4.x as shown below
Xcode 4.x (Git Submodule)
Add the submodule: git submodule add git://github.com/RestKit/RestKit.git RestKit
Open the project you wish to add RestKit to in Xcode.
Focus your project and select the "View" menu > "Navigators" > "Project" to bring the project file list into view.
Drag the RestKit.xcodeproj file from the Finder and drop it on your "".xcodeproj.
Click on your project's name in the sidebar on the left to open the project settings view in the right pane of the window.
In the middle pane you will see PROJECT and TARGETS headers for your project. Click on your project name, then select Build Settings along the top to open the Build Settings editor for your entire project.
Find the Header Search Paths setting. Double click and add a new entry. Add a search path to the "$(SOURCE_ROOT)/RestKit/Build" directory you have added to your project. DO NOT check the Recursive checkbox.
Find the Library Search Paths setting. Double click and add a new entry. Add a search path to the "$(SOURCE_ROOT)/RestKit/Build/$(BUILD_STYLE)-$(PLATFORM_NAME)" directory you have added to your project.
NOTE: This is only necessary if you are NOT using DerivedData.
Find the Other Linker Flags entry and double click it. Use the + button to add a new entry and enter -ObjC -all_load. Dismiss the editor with the Done button.
Locate the target you wish to add RestKit to in the TARGETS list in the middle of the editor pane. Select it to open the target settings editor in the right pane of the window.
Click the Build Phases tab along the top of the window to open the Build Phases editor.
Click the disclosure triangles next to the Target Dependencies and Link Binary with Libraries items.
In the Target Dependencies section, click the + button to open the Target selection sheet. Click on the RestKit aggregate target (it will have the bulls-eye icon) and click the Add button to create a dependency.
In the Link Binary with Libraries section, click the + button to open the Library selection sheet. Here we need to instruct the target to link against all the required RestKit libraries and several system libraries. Select each of the following items (one at a time or while holding down the Command key to select all of them at once) and then click the Add button:
libRestKitCoreData.a - Optional. Only necessary if you are using Core Data.
libRestKitJSONParserJSONKit.a
libRestKitNetwork.a
libRestKitObjectMapping.a
libRestKitSupport.a
CFNetwork.framework
CoreData.framework - Optional. Only necessary if you are using Core Data
MobileCoreServices.framework
SystemConfiguration.framework
libxml2.dylib - Optional. Only necessary if you are mapping from XML payloads and link libRestKitXMLParserLibxml.a into your app.
Verify that all of the libraries are showing up in the Link Binary with Libraries section before continuing.
Congratulations, you are now done adding RestKit into your Xcode 4 based project!
You now only need to add includes for the RestKit libraries at the appropriate places in your application. The relevant includes are:
#import <RestKit/RestKit.h>
// And if you are using Core Data...
#import <RestKit/CoreData/CoreData.h>
I found this tutorial very useful to make it work on xCode 4.0.
http://liebke.github.com/restkit-github-client-example/
I did my build following this steeps https://github.com/RestKit/RestKit/wiki/Installing-RestKit-in-Xcode-4.x and guoleii is right. But I needed to change the owner directory.
Have you seen this threads from RestKit's Google Group?
link 1
link 2
Try searching there. But for now, there seems to be A LOT of issues with RestKit and Xcode 4, there's even a YouTube video showing the problems (none showing a how-to).
did you build RestKit according to the wiki page "Installing RestKit in Xcode 4.x" on github.com/RestKit? i think there is a little mistake. here is my solution: 1. in "Build Phases" -> "Link Binary With Libraries", delete the RestKit.framework and add Security.frameWork 2. build again
then it works.
I just tried to install RestKit on a newly created Xcode 5 iOS 7.0 project. I tried downloading the project and following the steps above, but i was missing most of the content with in the RestKit/Vendor folder. After doing a bit of research i did the submodule tactic and that got me all of the information from those folders.
From the command prompt change directory into your project folder, for me it was
$ cd Documents/Projects/NewlyCreatedApp
From there you should run this command if you have no git repository
Note: you must download git to install this, if you have not already
$ git init
after that you must run these commands to download restkit into your project folder
$ git submodule add git://github.com/RestKit/RestKit.git
$ git submodule update --init --recursive
After that, you should go up to Nakkeeran's answer above and start from step 2, to set up the process. In step 7 you will be asked to add "$(SOURCE_ROOT)/RestKit/Build" to your header search paths, but upon closer inspection the RestKit framework no longer has the build folder so you should change that to "$(SOURCE_ROOT)/RestKit/Code" to fit the current version of Rest Kit
I hope this helps, and here is a link to the submodule information i posted.
RestKit Installation Submodule Method

How to use eclox, the doxygen plugin for Eclipse

How do I get eclox working in Eclipse 3.5?
I'm using Ubuntu 9.04. I installed Doxygen from ubuntu repositories(version 1.5.8). Then I installed eclox on eclipse through the update site.
Despite this, I don't get any option to in any menu to initiate it.
Also the eclox site doesn't seem to have any "getting started" guide.
Please help.
BTW there is a manual inside org.gna.eclox_0.8.0.jar, wierd they did not post this on the project site!!!
Here is the content
Eclox, a Doxygen frontend plugin for Eclipse.
<http://gna.org/projects/eclox>
INSTALLATION
There are two options to install the plugin: using the update site or
using the packaged feature.
The update site is the more convenient way to install eclox. It is
located at https://anb0s.github.io/eclox. See eclipse's user
guilde for additionnal details.
When using the packaged feature, you must extract the archive content into
your eclipse's root location. For additionnal details, please refer to
eclipse's user guide.
CONFIGURATION
Once the plugin installed, you must ensure that the default PATH environment
variable makes the doxygen binary reachable for the plugin. If not, you can
update PATH to include to directory containing the Doxygen binary, or you can
tell Eclox where that binary is located on your system (which is in my opinion
the better solution). To do this, open eclipse's preference edition dialog
window and go into the new "Doxygen" section.
USAGE
You can create new Doxygen projects (also called doxyfiles) using the
creation wizard. Go to "File->New->Other->Other->Doxygen Configuration". Press
next and set both file location and name. Then a empty doxyfile will be
created at the specified location, the wizard automatically adds the
".Doxyfile" extension.
You should now see a file with a blue #-sign icon. This is your new
doxyfile. Double-clicking on it will open the editor. You can now browse and
edit the settings.
Once your have properly set all doxyfile fields, you can launch a
documentation build using the toolbar icon showing a blue #-sign. In
the case the button is not visible in the toolbar, your current perspective
needs to get configured. Go to "Window->Customize perspective->Commands" and
in "Available command groups" check "Doxygen". Additionnaly, you can browse
the laetest builds by clicking the down arrow right to the toolbar button.
When the documentation build starts, a new view showing the build log opens.
In its toolbar, a button named "Stop" allows you to halt the current build
process. The current build also appears in the Eclipse job progress view and
you can control the job from there.
The build toolbar action determine the next doxyfile to build depending on
the current active workbench part (editor or view) and the current selection
in that part. For example, if the active part is a doxyfile editor, the next
doxyfile to build will be the one being edited. If the active part is the
resource explorer and the current selection is a doxyfile, that doxyfile will
be next to get build. In the case the active part selection doesn't correspond
to a doxyfile, the last built doxyfile will be rebuiled. And if the build
history is empty, you will be asked for the doxyfile to build.
HTH Anybody
Never mind, worked it out my self.
First you need to create a DoxyFile (which is the configuration file) by giving the source path and the output path.
Then only you can generate the documentation by right clicking the project and selecting the "Generate Documentation".
Thanks anyway!
I just faced a problem setting the Doxygen binary path in eclox 0.8.0 settings in Eclipse on Mac OS X 10.7.
There is no way to configure the path via Eclipse-preferences->Doxygen.
The solution is to edit the preferences file manually
add a (fake) location, let's say /Applications, using the wizard mentioned above.
close Eclipse
edit this file:
$WORKSPACE/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.gna.eclox.core.prefs:
Replace the value for doxygen.default (currently eclox.core.doxygen.CustomDoxygen /Applications\n) with eclox.core.doxygen.CustomDoxygen /Applications/Doxygen.app/Contents/Resources/doxygen\n.
restart Eclipse
For MacOS user there is a very easy way to get around via the issue of the Doxygen version selection. The link that provides details is here:https://github.com/theolind/mahm3lib/wiki/Integrating-Doxygen-with-Eclipse
After installing the Eclox plugging:
1)"go to "Eclipse --> Preferences --> Oxygen"
2)"Press Shift+CMD+G then Add: "/Applications/Doxygen.app/Contents/Resources/doxygen"
3) Doxygen's version should be displayed
this might help you or any windows user trying to install eclox:
Tutorial for Installing eclox — Document Transcript
Step 1: go to eclox website (http://home.gna.org/eclox/) and to copy the update link address.Step
step 2: Insert the link into the update manager in eclipse and press OK.
Step 3: Select the Eclox item and to complete the installation.
Step 4: When the installation has done, you should select a project that you want to generate thedoxygen documents. Then, create a doxygen project for it.
Step 5: config the options. Note: You have to provide the “Input directories” correctly and to select the “Scan recursively”item. Finally, save the configuration file.
Step 6: find out the “#” and to choice “Choose Doxyfile...”.
Step 7: select a doxyfile.Step 8: wait for few seconds and the doucments will be generated.
its from this link: http://www.slideshare.net/pickerweng/tutorial-for-installing-eclox
Like claus I had to dig into the preferences file maually, because eclox 0.8.0 would just not take a good path from Eclipse Preferences file chooser.
So, edit this file: $WORKSPACE/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.gna.eclox.core.prefs and alter the given path (in my case I had to change from
doxygen.default=eclox.core.doxygen.CustomDoxygen C\:\\Programm Files\\doxygen\\bin
to this
doxygen.default=eclox.core.doxygen.CustomDoxygen C\:\\Programme\\doxygen\\bin
Hope this helps.
I find a webpage https://github.com/theolind/mahm3lib/wiki/Integrating-Doxygen-with-Eclipse where you can find more details. Especially, for Mac users, you need to Press Shift+CMD+G then Add: "/Applications/Doxygen.app/Contents/Resources/doxygen" when you configure the doxygen in eclipse before compiling .doxygfile by using Eclox.
Alternative from eclipse is to use Javadoc:
From menu (...Search Project Run...)
Project > Generate Javadoc
You should be in Java project and add comments with tags.
!!!