Coldfusion wddx with indentation - coldfusion

I want to store my localization files in wddx format.
The problem is that sometimes I need to edit translation manually which might be a problem with wddx format as Coldfusion saves it in file as a single line.
Is there a way for me to format wddx string before saving it?
Leonti

I don't think ColdFusion natively supports indenting xml/wddx. So either you can use xmlindent from cflib.org or if you are comfortable with java there are many solutions available see this thread like
Transformer transformer = TransformerFactory.newInstance().newTransformer();
// indent and omit xml declaration
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
StreamResult result = new StreamResult(new StringWriter());
DOMSource source = new DOMSource(doc);
transformer.transform(source, result);
return result.getWriter().toString();

Related

F# execute XSL Transform from XML String and returns string

looking at the XSLCompiledTransform Class in .NET at trying to find a concise way to use it in F#. I am unfamiliar with string readers/writers but am looking at that as primary method to accomplish this. Or do I want XML readers?
I have a function that will take two arguments - an XML string and an XSLT stylesheet. I want to return a string of XML.
let applyXSLTransform xml xslFile =
let xslt = XslCompiledTransform()
xslt.Load(xslFile)
xslt.Transform(xml, outputToString); //This bit
It's nice and easy to do with files but seems a bit more involved to read and write to strings. I have seen a few C# samples and not having immediate success in getting them to work so still doing research onto readers and writers!
Cheers
I don't think there is an easier way to use the API than using the XmlReader and XmlWriter interfaces. This is unfortunately quite tedious, but the following should do the trick:
open System.IO
open System.Text
open System.Xml
open System.Xml.Xsl
let applyXSLTransform xml (xslFile:string) =
let xslt = XslCompiledTransform()
let sbuilder = StringBuilder()
use swriter = new StringWriter(sbuilder)
use sreader = new StringReader(xml)
use xreader = new XmlTextReader(sreader)
use xwriter = new XmlTextWriter(swriter)
xslt.Load(xslFile)
xslt.Transform(xreader, xwriter)
sbuilder.ToString()
The code constructs StringBuilder, which is an in-memory object for constructing strings. It wraps this around StringWriter and XmlTextWriter to be passed to the Transform method. At the end, you read the contents of the StringBuilder using the ToString method. Similar thing happens to create XmlTextReader for data from StringReader, which contains your input XML.
This is what I could come up with, trying to use the recommended XmlReader.Create factory methods instead of the .NET 1 legacy XmlTextReader:
open System
open System.Xml.Xsl
open System.Xml
open System.IO
let transform xml xslt =
let processor = XslCompiledTransform()
use xsltreader = XmlReader.Create(new StringReader(xslt))
processor.Load(xsltreader)
use xmlreader = XmlReader.Create(new StringReader(xml))
use resultwriter = new StringWriter()
processor.Transform(xmlreader, null, resultwriter)
resultwriter.ToString()
But I have no deep knowledge of F#, just tried to convert my C# coding way to F#.

QT C++ Project (Creating Login with XML)

I have question about my internship project. They want me to create a basic Login page(ID, Password). I create a XML file for Username and Password. The program should check the XML file for username and password*. If they are correct it will direct to a second window. I'm stuck on processing XML file for username and password. How can read those information in XML file.
As #JarMan said, I would recommend the QXmlStreamReader. You can fill it with a file (QIODevice), QString, QByteArray, etc...
Parsing a value could e.g. look like that
xml.attributes().value( attribute ).toString();
if attribute is a QString and xml is the QXmlStreamReader.
See the doc https://doc.qt.io/qt-5/qxmlstreamreader.html
There are several ways to do it. Marris mentioned one, but another one is to have this kind of code generated automatically. The way this works is that you first write an XML Schema that describes what your XML data looks like. An introduction to the XML Schema language can be found e. g. here.
Then you use an XML Schema compiler to translate the XML Schema to C++ classes. The schema compiler will also generate code to parse an XML file into objects, meaning you don't have to write any code to deal with XML by hand. It's a purely declarative approach: declare what the data looks like, and let the computer figure out the details.

Workbook gem - how to write the excel to html in a formatted manner?

I am using Workbook gem to preview the excel file without page breaks in my website. Right now, I am successful in extracting the excel file and writing it into html format and display as preview.
The following code extracts and writes the excel to html:
excel_file = Workbook::Book.open "#{file_url}"
excel_file.write_to_html(file_name + ".html")
But this gives me an unformatted html sheet with no rows and columns or any of the existing excel file.
According to murb/workbook documentation, it is said that we can pass the format as a hash within its options.
write_to_html(filename = "#{title}.html", options = {})
So, to achieve the format hash, I tried the following code:
excel_file.template.formats
But this returns a null hash. So, how can i get all the formats from the excel file and write to html? Or at least show the html table with borders for all rows and columns.
The author here. The Workbook gem is mainly built to extract and rerepresent the data in files, and not so much the formatting. In the past I made a few attempts on adding support to maintain formatting when converting, but it is far from complete. Some importers don't even set the formatting hash as you found out, notably the xlsx importer needs work on this.
The HTML was built to simply give a basic preview of the data. It basically returns a html-page with all tables which is by default unformatted, although format-names are used in the classes. There is an option though, if you'd pass style_with_inline_css: true... but then it requires an importer to actually set the format hash properly...
I'm happy to guide you here and there when you want to improve the xlsx importer code to suit your needs and hopefully the workbook gem in general, but it will need serious work if you want more than just some background colours and font properties.

JMeter - How to extract values from a response which has been decoded from base64 and stored in a variable? All under the same sampler

I am trying to test a webservice's performance, and having a few issues with using and passing variables. There are multiple sequential requests, which depend on some data coming from a previous response. All requests need to be encoded to base64 and placed in a SOAP envelope namespace before sending it to the endpoint. It returns and encoded response which needs to be decoded to see the xml values which need to be used for the next request. What I have done so far is:
1) Beanshell preprocessor added to first sample to encode the payload which is called from a file.
2) Regex to pull the encoded response bit from whole response.
3) Beanshell post processor to decode the response and write to a file (just in case). I have stored the decoded response in a variable 'Output' and I know this works since it writes the response to file correctly.
4) After this, I have added 4 regex extractors and tried various things such as apply to different parts, check different fields, check JMeter variable etc. However, it doesn't seem to work.
This is what my tree is looking like.
JMeter Tree
I am storing the decoded response to 'Output' variable like this and it works since it's writing to file properly:
import org.apache.commons.io.FileUtils;
import org.apache.commons.codec.binary.Base64;
String Createresponse= vars.get("Createregex");
vars.put("response",new String(Base64.decodeBase64(Createresponse.getBytes("UTF-8"))));
Output = vars.get("response");
f = new FileOutputStream("filepath/Createresponse.txt");
p = new PrintStream(f);
this.interpreter.setOut(p);
print(Output);
f.close();
And this is how I using Regex after that, I have tried different options:
Regex settings
Unfortunately though, the regex is not picking up these values from 'Output' variable. I basically need them saved so i can use ${docID} in the payload file for next request.
Any help on this is appreciated! Also happy to provide more detail if needed.
EDIT:
I had a follow up question. I am trying to run this with multiple users. I have a field ${searchuser} in my payload xml file called in the pre-processor here.
The CSV Data set above it looks like this:
However, it is not picking up the values from CSV and substituting in the payload file. Any help is appreciated!
You have 2 problems with your Regular Expression Extractor configuration:
Apply to: needs to be response
Field to check: needs to be Body, Body as a Document is being used for binary file formants like PDF or Word.
By the way, you can do Base64 decoding and encoding using __base64Decode() and __base64Encode() functions available via JMeter Plugins. The plugins in their turn can be installed in one click using Plugin Manager

How do I view the contents of an IXMLDOMElementPtr when building an XML file?

I'm using IXMLDOM in MSXML 6 to build an XML file in a C++ MFC application. Is there a way to see the contents of the xml document while it is in memory?
For example, an XPATH query is failing about halfway through creating the file. How would I view the entire contents of the xml doc?
Thanks!
IXMLDOMElement derives from IXMLDOMNode, and IXMLDOMNode has an xml property that you can use to get the textual representation of the XML in memory.
IXMLDOMElementPtr spElement = ...;
_bstr_t xmlContents = spElement->xml();
If you're looking for a way to see the contents of the XML in the debugger without changing existing code to add this call, that may be possible, but I'm not exactly sure where to look.