I have a template fragment file, which is an xml file in fact.
I want to load it in my controller, do some modification on that, and then use it to render some part of the view.
I only need to read this xml file as text file and put its content in a string.
I cannot find any object for doing this in SAPUI5 api.
Please note the file is placed in my view folder in server side.
I need some kind of promise that read the file and after reading the file run a successor function.
Thanks in advance
There can be multiple ways to to this.
1.Either you can load your XML in an XML Model "sap.ui.model.xml.XMLModel()"
var oModelX = new sap.ui.model.xml.XMLModel();
oModelX.attachRequestCompleted(function(){
var xmlStr = oModelX.getXML();
console.log(xmlStr); // Do what ever you want with your xml string
});
oModelX.loadData("../view/st.fragment.xml");
2.You can also read the content of that XML file using AJAX and do your parsing in AJAX response.
Related
How can I convert the TYPO3 file uri t3://file?uid=54 to be usable for other TYPO3 methods which need a file identifier?
The file uri is returned by a flexform which selects a XML file. This XML file should be read.
However I cannot find a useful API function in the TYPO3 Core.
$paramTestFile = 't3://file?uid=54';
$xmlString = GeneralUtility::getURL($paramTestFile);
The above code fails for TYPO3 URIs.
The file reference with uid=54 is at "fileadmin/example.xml".
The Filelist backend module shows the details of this file.
However I need this file path also in the PHP code in order to read in the file.
use TYPO3\CMS\Core\LinkHandling\FileLinkHandler;
$fileHandler = GeneralUtility::makeInstance(FileLinkHandler::class);
$fileInfo = $fileHandler->asString($paramTestFile);
It is not possible to use $paramTestFile in the above example.
The class FileLinkHandler and its method asString does exactly the opposite of what I need.
$content = #file_get_contents($url);
However the absolute file path is needed for the read method . How can I convert the FAL file URI into the file identifier?
use TYPO3\CMS\Core\Resource\StorageRepository;
$storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
$defaultStorage = $storageRepository->getDefaultStorage();
$fileInfo = $defaultStorage->getFileByIdentifier($paramTestFileIdentifier);
To resolve a t3://file... URN use TYPO3\CMS\Core\LinkHandling\LinkService::resolve(). This method will return an array with a key file containing a TYPO3\CMS\Core\Resource\FileInterface. This also works for other URNs but will return another array structure.
Then use the getContents() method of the FileInterface to finally get the content of the file.
The documentation is not very detailed for this part of the core so I have linked you directly to the related sources.
I need to export a Domino document with RTF (images, tables, etc) to MS.Word in background mode or via Web. I have tried with POI4Xpages but I don't know how to export it.
You need to write your POI document to an output stream. This could be a fileOutputStream or the response. When using the response you need to set the header to reflect the file type. Check for XAgent for a sample how to do that. See: https://www.wissel.net/blog/2008/12/xagents-web-agents-xpages-style.html
I'm using OpenXml SDK to generate word 2013 files. I'm running on a server (part of a server solution), so automation is not an option.
Basically I have an xml file that is output from a backend system. Here's a very simplified example:
<my:Data
xmlns:my="https://schemas.mycorp.com">
<my:Customer>
<my:Details>
<my:Name>Customer Template</my:Name>
</my:Details>
<my:Orders>
<my:Count>2</my:Count>
<my:OrderList>
<my:Order>
<my:Id>1</my:Id>
<my:Date>19/04/2017 10:16:04</my:Date>
</my:Order>
<my:Order>
<my:Id>2</my:Id>
<my:Date>20/04/2017 10:16:04</my:Date>
</my:Order>
</my:OrderList>
</my:Orders>
</my:Customer>
</my:Data>
Then I use Word's Xml Mapping pane to map this data to content control:
I simply duplicate the word file, and write new Xml data when generating new files.
This is working as expected. When I update the xml part, it reflects the data from my backend.
Thought, there's a case that does not works. If a customer has no order, the template content is kept in the document. The xml data is :
<my:Data
xmlns:my="https://schemas.mycorp.com">
<my:Customer>
<my:Details>
<my:Name>Some customer</my:Name>
</my:Details>
<my:Orders>
<my:Count>0</my:Count>
<my:OrderList>
</my:OrderList>
</my:Orders>
</my:Customer>
</my:Data>
(see the empty order list).
In Word, the xml pane reflects the correct data (meaning no Order node):
But as you can see, the template content is still here.
Basically, I'd like to hide the order list when there's no order (or at least an empty table).
How can I do that?
PS: If it can help, I uploaded the word and xml files, and a small PowerShell script that injects the data : repro.zip
Thanks for sharing your files so we can better help you.
I had a difficult time trying to solve your problem with your existing Word Content Controls, XML files and the PowerShell script that added the XML to the Word document. I found what seemed to be Microsoft's VSTO example solution to your problem, but I couldn't get this to work cleanly.
I was however able to write a simple C# console application that generates a Word file based on your XML data. The OpenXML code to generate the Word file was generated code from the Open XML Productivity Tool. I then added some logic to read your XML file and generate the second table rows dynamically depending on how many orders there are in the data. I have uploaded the code for you to use if you are interested in this solution. Note: The xml data file should be in c:\temp and the generated word files will be in c:\temp also.
Another added bonus to this solution is if you were to add all of the customer data into one XML file, the application will create separate word files in your temp directory like so:
customer_<name1>.docx
customer_<name2>.docx
customer_<name3>.docx
etc.
Here is the document generated from the first xml file
Here is the document generated from the second xml file with the empty row
Hope this helps.
is it possible to use the OPEN XML SDK and generate an xml file that contains some metadata of a particular docx file?
details: i have a docx file, from which i want to extract some metadata(using open xml) and display them as xml file and later use Jquery to present them in a more readable form.
You can use the SDK to extract info from the various properties parts which may be present in the docx (for example, the core properties part, which included dublin core type info).
You can extract it in its native XML form:
<cp:coreProperties
xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core- properties"
xmlns:dc="http://purl.org/dc/elements/1.1/" .. >
<dc:creator>Joe</dc:creator>
<cp:lastModifiedBy>Joe</cp:lastModifiedBy>
<cp:revision>1</cp:revision>
<dcterms:created xsi:type="dcterms:W3CDTF">2010-11-10T00:32:00Z</dcterms:created>
<dcterms:modified xsi:type="dcterms:W3CDTF">2010-11-10T00:33:00Z</dcterms:modified>
</cp:coreProperties>
or, in some other XML dialect of your own choosing.
I know question was posted a long time ago, but first result of google search sent me here. So if there are others looking for a solution to this, there is a snippet on MSDN website https://msdn.microsoft.com/en-us/library/office/cc489219.aspx
short answer is... using XmlTextWritter, and it applies to Office 2013 afaik:
// Add the CoreFilePropertiesPart part in the new word processing document.
var coreFilePropPart = wordDoc.AddCoreFilePropertiesPart();
using (XmlTextWriter writer = new XmlTextWriter(coreFilePropPart.GetStream(FileMode.Create), System.Text.Encoding.UTF8))
{
writer.WriteRaw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<cp:coreProperties xmlns:cp=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\"></cp:coreProperties>");
writer.Flush();
}
I have a large amount of data in an XML file, and I'd like to append data to this file without rewriting it every time. I already know how to write the entire file out, but I'm struggling with how to append data to this file. Do you have a suggestion for how to do this?
XML isn't a good format for this - if you append to a previously-complete document, it's no longer a complete document.
One option (depending on the APIs available to you) is not to write the root tag or document declaration, but to fake them when you read the file. So you'd have:
Fake document declaration
Fake root open tag
Real data from the file
Fake root close tag
Then you can just append elements to the end of your file at will. It will depend on what you're trying to do with this file though - and whether you can fake a stream input which effectively "tops and tails" the real data in the file.