XSD.exe changes parameters - xsd

I'm currently working with the XSD.exe tool to get classes of XSD files.
But when I pass a file to the tool, it changes the path/file.
string fileName = "C:\\TEST\\testFILE.xsd";
Process p = new Process();
p.StartInfo = new ProcessStartInfo("C:\\xsd.exe", "/c /language:CS " + fileName);
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.UseShellExecute = false;
p.Start();
StringBuilder error = new StringBuilder();
while (!p.HasExited)
error.Append(p.StandardError.ReadToEnd());
MessageBox.Show(error.ToString());
Thats some example code to show you the problem.
The output looks like:
Error: Could not find file "c:\test\testfile.xsd
Of course there is no such file or directory.
Do you guys have any idea how to solve this?
Thank ;)

I found the problem. The path in the above given example is a bad choice. In fact, the path I'm really using contains spaces. The XSD.exe uses spaces to seperate arguments. So you have to add some extra quotations at the beginning and at the end of the path string.
For example :
string cmdPath= String.Format(#"""{0}""", path);

Related

Trying to delete sharpoint file with a "#" in the name

A lot of the documents I’m dealing with at the moment have a “#” in the file name and when listing the files in the folder I got around this issues by doing a simple replace of the encoded value of %25
var fileRefOriginal = file.ServerRelativeUrl;
var fileRef = fileRefOriginal.Replace("#", "%23");
var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(sourceContext, fileRef);
using (var fileStream = System.IO.File.Create(fileName))
{
fileInfo.Stream.CopyTo(fileStream);
}
But for some of the files I need to delete and I was just using this after the download;
sourceContext.Web.GetFileByServerRelativeUrl(fileRef).DeleteObject();
sourceContext.ExecuteQuery();
but it wasn’t removing anything and didn’t give an error so I tried this which just says file not found;
var f = sourceContext.Web.GetFileByServerRelativeUrl(fileRef);
sourceContext.Load(f);
f.DeleteObject();
sourceContext.ExecuteQuery();
I’ve tried it with the original name and the converted name (using %25) but seem to be getting no where.
Got this to work, by capturing the files unique ID, then instead of using ;
var f = sourceContext.Web.GetFileByServerRelativeUrl(fileRef);
I used this;
var f = sourceContext.Web.GetFileById(fileId);
Hope it helps someone with the same issue.

eval() is not working properly

I get the following error while trying to evaluate a predicate in a a4solution:
Fatal error in /some/path at line 9 column 2: Field "field
(A/Attribute <: type)" is not bound to a legal value during
translation.
Here is the code at the origin of the error:
for(ExprVar a : solution.getAllAtoms()){
// additional checks are here to assure that a is of an "appropriate type"
solution.eval(predicate.call(a));
}
In my vain attempts to solve this problem by myself, I read from this source http://code.google.com/p/alloy4eclipse/issues/detail?id=86 that the way the solution has been read from the file might cause this problem.
But the source doesn't give further details.
I have created my solution object as follows :
XMLNode xml = new XMLNode(new StringReader(source.getFileContent()));
this.solution = A4SolutionReader.read(new ArrayList<Sig>(), xml);
Thank you for your support
The problem was that the expression to be evaluated (predicate.call(a)) was drawn from one CompModule object (namely the predicate function was taken from there) while the solution object, against which the expression was evaluated, was not obtained from the same CompModule, but was read from a file.
Generally, when reading a solution from an xml file, to be on the safe side, it is recommended to reread and reconstruct everything from that xml file, e.g.,
XMLNode xmlNode = new XMLNode(new File("my_solution.xml"));
String alloySourceFilename = xmlNode.iterator().next().getAttribute("filename");
Module module = CompUtil.parseEverything_fromFile(rep, null, alloySourceFilename);
A4Solution ans = A4SolutionReader.read(module.getAllReachableSigs(), xmlNode);
In some cases it suffices to just pass the sigs from the original CompModule to the reconstructed solution:
XMLNode xmlNode = new XMLNode(new File("my_solution.xml"));
A4Solution ans = A4SolutionReader.read(originalModule.getAllReachableSigs(), xmlNode);

How to write into XML file in Haxe?

I am using Haxe and OpenFL and I got a program that generates a Xml file.
However, I can't figure out how to save that file. I can create Xml tree and check it's valid, but for my life I can't figure out how to write the file.
So, in simple, how to do I write(and create) a file in Haxe? I want to be able to save my newly created Xml File (they serve as sort of settings file and initialization files for my program) on computer, so that I can load it later?
Found the solution right after writing this question.
Solution is to first to use sys.io.File.write() to create the file, then File.saveContent() to save the data in. You can get string from Xml with toString function, the ultimate solution looks like this:
if (!FileSystem.exists("maps"))
{
FileSystem.createDirectory("maps");
}
var number:Int = 1;
if (FileSystem.exists("maps/" + filename + ".xml"))
{
while(FileSystem.exists("maps/" + filename + number +".xml"))
{
number++;
}
filename = filename + number;
}
File.write("maps/" + filename + ".xml", false);
File.saveContent("maps/" + filename + ".xml", root.toString());
This checks if the directory exist and if not, create it and if the file exist, create a new numbered file rather than override it (for the moment, still working on the save feature)
This solution only works on c++, haven't tested others much yet but Flash does not work

Remove all previous text before writing

I am writing a text file and each time i write i want to clear the text file.
try
{
string fileName = "Profile//" + comboboxSelectProfile.SelectedItem.ToString() + ".txt";
using (StreamWriter sw = new StreamWriter(("Default//DefaultProfile.txt").ToString(), true))
{
sw.WriteLine(fileName);
MessageBox.Show("Default is set!");
}
DefaultFileName = "Default//DefaultProfile.txt";
}
catch
{
}
How do I do this? I want to remove all previous content from DefaultProfile.txt.
I actually have to know the method or way (just a name could be) to remove all content from the text file.
You could just write an empty string to the existing file:
File.WriteAllText(#"Default\DefaultProfile.txt", string.Empty);
Or change the second parameter in the StreamWriter constructor to false to replace the file contents instead of appending to the file.
You can look at the Truncate method
FileInfo fi = new FileInfo(#"Default\DefaultProfile.txt");
using(TextWriter txtWriter = new StreamWriter(fi.Open(FileMode.Truncate)))
{
txtWriter.Write("Write your line or content here");
}
The most straightforward and efficient technique is to use the StreamWriter constructor's boolean parameter. When it's set to false it overwrites the file with the current operation. For instance, I had to save output of a mathematical operation to a text file. Each time I wanted ONLY the current answer in the text file. So, on the first StreamWriter operation, I set the boolean value to false and the subsequent calls had the bool val set to true. The result is that for each new operation, the previous answer is overwritten and only the new answer is displayed.
int div = num1 / denominator;
int mod = num1 % denominator;
Console.Write(div);
using (StreamWriter writer = new StreamWriter(FILE_NAME, false ))
{
writer.Write(div);
}
Console.Write(".");
using (StreamWriter writer = new StreamWriter(FILE_NAME, true))
{
writer.Write(".");
}
You can use FileMode.Truncate. Code will look like
FileStream fs = new
FileStream(filePath, FileMode.Truncate, FileAccess.Write )
{
fs.Close();
}
System.IO.File.Delete, or one of the System.IO.FileStream constructor overloads specifying FileMode.Create
Simply change the second parameter from true to false in the contructor of StreamWriter.
using (StreamWriter sw = new StreamWriter(("Default//DefaultProfile.txt").ToString(), **false**))
See StreamWriter Contructor

Is there a way to get all embedded objects in .xlsx file using xssf event mdel api

Is there a way to get all embedded objects in .xlsx file using xssf event model api?
Usermodel has the method workbook.getallembedds...similarly is there anything in eventmodel?
This is an example in usermodel.I want to implement the same functionality using eventusermodel.Kindly help.
for (PackagePart pPart : workbook.getAllEmbedds()) {
String contentType = pPart.getContentType();
if (contentType.equals(------)
Instead of xssfworkbook(in usermodel), in the eventmodel code i have a containerObject of type OPCPackage.
#Gagravarr : Thanks for your reply. I tried using the method suggested by you...but im unable to get the contents of the embedded excel.Could you please help me find out where I am going wrong.Here is a part of the code:
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(container);
XSSFReader xssfReader = new XSSFReader(container);
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator)xssfReader.getSheetsData();
for(PackageRelationship rel : iter.getSheetPart().getRelationshipsByType(XSSFRelation.OLEEMBEDDINGS.getRelation()))
embedds.add(getTargetPart(rel));
for (PackagePart pPart :getAllEmbedds()) {
String contentType = pPart.getContentType();
// Excel Workbook - OpenXML file format
if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml")) {
OPCPackage excelObject = OPCPackage.open(pPart.getInputStream());
`
Your best bet is probably just to enumerate all the package parts, and find the ones that interest you from that
Alternately, the logic to identify embedded parts attached to a given sheet is pretty simple:
List<PackagePart> embedds = new LinkedList<PackagePart>();
// Get the embeddings for the workbook
for(PackageRelationship rel : sheet.getSheetPart().getRelationshipsByType(XSSFRelation.OLEEMBEDDINGS.getRelation()))
embedds.add(getTargetPart(rel));
for(PackageRelationship rel : sheet.getSheetPart().getRelationshipsByType(XSSFRelation.PACKEMBEDDINGS.getRelation()))
embedds.add(getTargetPart(rel));
return embedds;
Finally all I used was this!
ArrayList<PackagePart> parts = container.getParts();
for (PackagePart pPart :parts) {
String contentType = pPart.getContentType();
if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {

Resources