Docxtemplater inserting plain xml - javascript

I am using DocxTemplater library by edi9999 as a solution for creating .docx reports from template and JSON data, and I am happy with this.
However, now I have to highlight some words in my reports. For example, I need to substitute {contents} with some large text, where few words are highlighted.
It means that I have 2 solutions here:
Use some kind of markers inside of my data (like in this data one {highlight(red)}{word} is red, which are then interpreted by DocxTemplater.
Directly substitute tag with desired xml. For example, I substitute {contents} with this xml (stored in my JSON data as "contents" field): <w:r> <w:rPr> <w:highlight w:val="cyan"/>
</w:rPr> <w:t>lol</w:t> </w:r>. If I do this now, I get my XML embedded in <w:r><w:t>HERE</w:t></w:r>, so that MS Word thinks that file is corrupt.
For "raw" xml data I want to use some kind of special tag like {#myXmlData}, which will prevent library from surrounding contents with <w:r><w:t></w:t></w:r>.
I think that second solution is many ways superior and it is very flexible: it allows users to use DocxTemplater even if it doesn't satisfy some of their needs. They can just use XML for their very specific needs.
I think it is really great new feature for DocxTemplater library.
However, now I just want to solve my problem and I don't have time to thoroughly study or modify library's code.
It would be great if someone will point to places in library's code and ideas of how to easily extend it to add this feature.
EDIT: now this feature is supported! Check out https://github.com/edi9999/docxtemplater/issues/7

I have implemented this indeed after https://github.com/edi9999/docxtemplater/issues/7
You can write
In your docx:
{#rawXml}
In your data:
{
rawXml:'<w:p> <w:r> <w:rPr> <w:highlight w:val="cyan"/></w:rPr> <w:t>lol</w:t> </w:r> </w:p>'
}

Related

xml data from API has multiple undefined name spaces - how to use xslt to display it in html?

I am using a REST api to get XML data from a database and am trying to display it in an html format using xslt. Unfortunately the xml data comes back with a few namespaces that are not defined. I can get the style sheet to work just fine on a local copy of the data if I strip the namespaces or define them. Striping the name spaces feels like a hack and no the correct way to do this.
this is essentially an example of the data I get back:
<root>
<entity:Entity ns1:atrib="foo">
<g:Value>foo1</g:value>
<g:Name>fooName</g:Name>
</entity:Entity>
xmlhttprequest methods in JS to get this information and XSLTProcessor to transform it then add it into a . It's not displaying the transformed information and i'm 100% positive it's the namespaces that is causing the issue.
I've googled everything I can think of with no luck. Road blocks like this are almost always due to me missing something fundamental.
XSLT will only operate on XML that is well-formed, and it requires all namespaces to be declared. If you want to process this data you should ideally fix it at source; if you can't do that you need to repair it before processing.
There are some XML parsers that allow you to process non-namespace-aware XML, and you could use such a parser as the basis of your repair tool, but this is such an unusual requirement that I'll have to leave you to research how to do that yourself.

How to convert Netscape-Bookmark-File-Format into well formed XML to manipulate

I have exported Netscape-Bookmark-Files as .html from Chrome, IE, and Firefox. These files are similar. Is there a way to convert this .html file into well-formed XML, for example, to view it in a TreeView in WPF? Or is there a workaround for that?
Maybe there is a better way to exchange Bookmarks under the Browsers which I don't know. Something like the JSON Files maybe....
I have to do a Project(C#) in which I have to program a little Bookmark Manager which I can Import and Export this HTML files as well as my own Bookmarks which are saved in a Database.... Do you have a better idea for this?
Please help me....
Regards
But i dont have JSON Files. I only have this f...ed up Netscape Bookmark File Format to work with. There is no Documentation for this Format. Only a poor one on Microsoft....
Treat each HTML <DT> tag like a new line.
In whatever language you have access to wrap each new line into a format that jstree.js can read so you end up with format as described here,
or simply use:
[{ id:lineCount, text:linedata},{rince and repeat}]
Then in whatever page you are using to display your tree load the json and you are good to go. Be careful you do not publish it openly as this writer would be concerned about any embeded authorization codes.
Another level of tricky would be to make each heading a parent. So in your preprocess you would create children object according to the above spec. As simple directory like re-entrant method (like you were going through a directory tree) would be able to child each group.
Then you would have
[{ id:lineCount, text:linedataParent, children[{id:lineCount, text:child, rince and repeat}, id:lineCount, text:nextParent, children:[{..and so on..}]...}]
Resulting in a somewhat nicer jsTree with parent/children the way you intended when you did your bookmark management.
Pretty sure this wont get voted best answer but it might be a start for you.

Converting Excel Data to a Chart in HTML dynamically

Is it possible to be able to upload an excel document with varying ranges of data, and have that data dynamically displayed in a basic form of chart(bar, pie, etc.) on our company website.
After doing some research I figured the only two possible ways to maybe do something like this is to use a very complicated macro in VBA or a Javascript parser to read the data and display it then. The data that will eventually go in here will have sensitive information so I cannot use google charts or anything like that.
This problem has to be divided into two parts.
One -part is to gather and process the information needed to display the chart.
Second - This is the easiest, a way to display a chart in HTML. For this, you can use www.c3js.org javascript library to display the chart in HTML.
Regarding part one, it depends in which technology is built your website.
For example, If it is in php, you will need to find a library in php, which can read and parse excel files.
Then you have to create a service in your website, where the data is going to be provided. For example,
www.yourcompany.com/provideChartData.php
You can format the response as json format.
Once you have solved that, you only have to call the service from your page, and the data will be dynamically displayed. You can call it using jquery library for javascript ($.post("www.yourcompany.com/provideChartData.php",function (data) { code to display chart ....}))
There is no real easy way to do this that I have found. I have had to manually parse these things in the past but there are some libraries out there for node that might help you.
https://www.npmjs.com/package/node-xlsx
You can also export form excel as CSV. When you do this, me sure to set the custom separator to something other than ',' and you should be fine to import it into a large array and get the data/charts you need.
https://github.com/wdavidw/node-csv
Hope that helps.

How should I parse XML-like data in JavaScript?

I have data sets similar to this:
<NDL>
<REPLICA 4925770B:0025BA85>
<VIEW OF64623968:A2336DB0-ON49256C46:002ACF42>
<NOTE OFA52D3E8C:0ED3F84A-ON605F586A:5D1C1FAA>
<HINT>CN=YW8LN6/O=TDK-JP</HINT>
<REM>Database 'Shunya Sato', View '受信ボックス', Document '[Requirement management system - Feature #125] (New) Collect example of LN link'</REM>
</NDL>
I need to retrieve the content enclosed by the <HINT> tag, and the pseudo-attributes in the , and tags. Is there some lib that could help me out with this, or is the best way to hope that everything will always be in this order and use split/find/other builtin stuff?
Unfortunately, unless you write a custom parser that can turn what you have into XML, you won't be able to use any traditional XML libraries to read your data. The only reason that people can perform XML queries over HTML is because there are clearly defined ways to convert HTML into a DOM, which can then be converted into XML. The same cannot be said for your data.
While your data may resemble XML, the only thing it has in common is the use of < and > to delimit fields. As such, you are probably just better off using string searching and spliting to get the fields you need.

How to display information contained in XML file from another website

I have an XML file ( XML file I produce ) which contains information about my parteners.
I want them to display on their website information relative to them by picking them into the XML file.
I have no idea to do that, ecxept that i need to write a 'parser' in javascript to display information. This javascript code i guess has to be on my partener's website.
could you please provide me examples to do that ? (how to write a parser, how to display only information for one partener ?)
Thank you,
Regards
I think this is a standard problem. Each browser does expose there own version of a Document type object which you can build and then use method like getElementByTagName to grab a particular node in the XML and process its data.
Few links which you can look at
http://www.hiteshagrawal.com/javascript/javascript-parsing-xml-in-javascript
http://www.mikechambers.com/blog/2006/01/09/parsing-xml-in-javascript/
I would suggest you to use prototype library for dealing with this

Categories