reading XML file with QDomElement and tag in c++ - qt

I have an XML file like this:
<studentsform>
<student Studentname="srikanth" Address="1-66-1" SSC_marks="75%" Inter_marks="82%" Btech_marks="65%" Mailid="srikanth.togara#gmail.com"/>
</studentsform>
How can i read this XML file in to lineedits of qt designer
Please help me

Parsing through an xml file is fairly easy, but is not a trivial answer. Take a look here for some instructions on how to parse the xml file.
For specific reading of (assuming you have moved to the correct location in the file) you can use something like this:
// Get and attribute with name 'Studentname', currentPos is a QDomElement*
QString retVal = currentPos->attribute("Studentname", "");
or you can get all the attributes and parse them manually using:
QDomNamedNodeMap attrMap = currentPos->attributes();

Related

How to get rid of the original file path instead of name in PGP encryption with ChoPGP library?

I tried PGP encrypting a file in ChoPGP library. At the end of the process it shows embedded file name along with the whole original file name path.
But I thought it will show only the filename without the whole path. Which I intend to work on and figure out a way to do so?
Doing the following:
using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt())
{
pgp.EncryptFile(#"\\appdevtest\c$\appstest\Transporter\test\Test.txt",
#"\\appdevtest\c$\appstest\Transporter\test\OSCTestFile_ChoPGP.gpg",
#"\\appdevtest\c$\appstest\Transporter\pgpKey\PublicKey\atorres\atorres_publicKey.asc",
true,
true);
}
which will result in:
But I would like to only extract the Test.txt in the end something
like this:
Looking at this line from the ChoPGP sources: https://github.com/Cinchoo/ChoPGP/blob/7152c7385022823013324408e84cb7e25d33c3e7/ChoPGP/ChoPGPEncryptDecrypt.cs#L221
You may find out that it uses internal function GetFileName, which ends up with this for the FileStream: return ((FileStream)stream).Name;.
And this one, according to documentation, Gets the absolute path of the file opened in the FileStream..
So you should either make fork of ChoPGP and modify this line to extract just filename, or submit a pull request to the ChoPGP. Btw, it's just a wrapper around the BouncyCastle so you may use that instead.

Save an Excel sheet as PDF programatically through powerbuilder

There is a requirement to save an excel sheet as a pdf file programmatically through powerbuilder (Powerbuilder 12.5.1).
I run the code below; however, I am not getting the right results. Please let me know if I should do something different.
OLEObject ole_excel;
ole_excel = create OLEObject;
IF ( ole_excel.ConnectToObject(ls_DocPath) = 0 ) THEN
ole_excel.application.activeworkbook.SaveAs(ls_DocPath,17);
ole_excel.application.activeworkbook.ExportAsFixedFormat(0,ls_DocPath);
END IF;
....... (Parsing values from excel)
DESTROY ole_excel;
I have searched through this community and others for a solution but no luck so far. I tried using two different commands that I found during this search. Both of them return a null object reference error. It would be great if someone can point me in the right direction.
It looks to me like you need to have a reference to the 'activeworkbook'. This would be of type OLEobject so the declaration would be similar to: OLEobject lole_workbook.
Then you need to set this to the active work book. Look for the VBA code on Excel (should be in the Excel help) for something like a 'getactiveworkbook' method. You would then (in PB) need to do something like
lole_workbook = ole_excel.application.activeworkbook
This gets the reference for PB to the activeworkbook. Then do you saveas and etc. like this lole_workbook.SaveAs(ls_DocPath,17)
workBook.saveAs() documentation says that saveAs() has the following parameters:
SaveAs(Filename, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution, AddToMru, TextCodepage, TextVisualLayout, Local)
we need the two first params:
FileName - full path with filename and extension, for instance: c:\myfolder\file.pdf
FileFormat - predefined constant, that represents the target file format.
According to google (MS does not list pdf format constant for XLFileFormat), FileFormat for pdf is equal to 57
so, try to use the following call:
ole_excel.application.activeworkbook.SaveAs(ls_DocPath, 57);

Save an image to outside the directory in asp.net

I am trying to save an image to server.Server directory structure is as follows
httpdocs-
Folder-
Page.aspx
and
httpdocs-
Images-
Subimages
The Folder and Images are under the httpdocs. I need to save the image to subimages folder from pages.aspx. Saving image code is on pages.aspx.
I tried
string CroppedImagePath = Server.MapPath("~/Images/Subimages"+file)
But not get the exact result
Unless file contains a leading / character, that's going to end up saving as something like:
~/Images/Subimagesfilename.ext
Use Path.Combine() to build a path name. Something like this:
var CroppedImagePath = Path.Combine(Server.MapPath("~/Images/Subimages"), file);
try this
string CroppedImagePath = Server.MapPath("~/Images/Subimages/"+file)
/ after Subimages

Get the real extension of a file vb.net

I would like to determine real file extension.
example :
file = "test.fakeExt"
// but the real extention is .exe // for security reason I wish to avoid using it!
How can I do that?
If you want to determine the extension you could use findmimefromdata.
It looks at the first part of the file to determine what type of file it is.
FindMimeFromData function
Sample code
The first two bytes of an .exe file are allways 'MZ'.
So you could read the binary file, and see if the first two bytes are MZ, then you know it's an .exe file...

Messy code while modifying the xml file with installscirpt

We want to modify the node of an xml file such as web.config and we get messy code after saving the file. The code we use is below:
set xmlDocument = CoCreateObject("Msxml2.DOMDocument.4.0");
if (!IsObject(xmlDocument)) then
return -1;
endif;
xmlDocument.async=FALSE;
xmlDocument.setProperty("SelectionLanguage","XPath");
xmlDocument.load(xmlFileName);
if(IsObject(xmlDocument)=FALSE) then
return -1;
endif;
set xmlNode = xmlDocument.selectSingleNode(nodePath);
if(IsObject(xmlNode)=TRUE) then
xmlNode.Attributes.getNamedItem("value").nodeValue = value;
xmlDocument.save(xmlFileName);
I tried to use many ways to resolve this problem, such as BOM or Encoding in xml file head.
But I haven't found the right way.
Now I would like to know two things:
the modifed file encoding.
modify the file with its encoding.
who can help me?

Resources