We have an old legacy system that where a component is writter in VB6. One method returns a string that is xml data. The xml data is created with msxml3.dll MSXML2.DOMDocument and returns the data of the document with the property xml: http://msdn.microsoft.com/en-us/library/ms755989(v=VS.85).aspx
However, some data of the xmldocument is from the database and one field is a hashed password string. The code that set the data for the element:
Set cellNode = rowNode.appendChild(xml.createElement("COL"))
If IsNull(rs(oField.name).Value) Then
cellNode.Text = ""
Else
cellNode.Text = rs(oField.name).Value
End If
This gives me malformed/non-wellformed xml:
<ROWS><ROW><COL>r<í</COL></ROW></ROWS>
Is there a workaround for this?
You should escape unicode characters. Or put them in a CDATA tag (which is not such a nice solution though)
Btw < > and & should be escaped as well.
Related
I am getting form fields from the PDF document but I did not see any method for getting form field format ForExample there are multiple text form fields in my document including Number field, Date field, Percentage field.
Is there any way to get field format type in itext7
#Uladzimir Asipchuk
/TU dictionary contains ToolTip value. Format value is contained in /AA >> /K dictionary in PDF structure. However I have extracted the JS Method after some tries and exploring the PDF structure through Pre-Flight. The following code snippet give the associated JSMethod if any:
PdfDictionary additionalActions = formField.GetAdditionalAction();
if (additionalActions != null)
{
PdfDictionary formatDictionary = additionalActions.GetAsDictionary(PdfName.K);
PdfString jsMethod = formatDictionary.GetAsString(PdfName.JS);
string fieldJsMethod = jsMethod.GetValue();
}
I created a pdf via Adobe (as you suggested) and I indeed was able to set the "format" of a text field as Date, Number, Percentage, Email,..
Then I opened the resultant pdf in RUPS (an utility program used to open the pdf's tree) and investigated it.
It turned out that Adobe sets the "format" which you want to get as a /TU value of the field's dictionary. For example, for Percentage it's percentfield and for Email - emailfield.
Now the only thing you need to find the "format" of your fieeld is to get the value of /TU entry of your field:
field.getValue().getPdfObject().get(PdfName.TU)
I need to compare 2 xml files using QTP where the values for each tag needs to be compared and need to print the difference in values if found. I used the built in Function XMLUTIL but its not working as expected i.e.. its creates a file with differences including the parent tag.
<tns:AAL_Request_NEW xsi:schemaLocation="http://www.bnymellon.com/AAL_Request_NEW AAL_Request_NEW.xsd">
<tns:OPF_Information>
<tns:Source>
<tns:Source>EPH</tns:Source>
</tns:Source>
<tns:References>
<tns:Accounting_Record_Reference>130830000672401</tns:Accounting_Record_Reference>
<tns:OPF_Reference>EPH1308300006724</tns:OPF_Reference>
<tns:Group_Reference>EPH1308300006723</tns:Group_Reference>
</tns:References>
</tns:OPF_Information>
</tns:AAL_Request_NEW>
In the above xml file i just need the tags with values like
tns:Source with value EPH, tns:Accounting_Record_Reference with value 130830000672401, tns:OPF_Reference with value EPH1308300006724 and tns:Group_Reference EPH1308300006723 to be compared and not the parent tags like tns:References, tns:OPF_Information or tns:AAL_Request_NEW.
Can anyone help with the logic to fetch the tags which has no child tag inside it and ends immediately with having only a value between its start <> and end and compare it with the other file and print the tag name and the values if there is a difference?
you can use CreateObject("Microsoft.XMLDOM") to read the xml files and retrive the tags by tag name and comparte them both.
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("<XML PATH>")
Set Root = objXMLDoc.documentElement
Set tags = root.tagnames
Set NodeList = Root.getElementsByTagname("<node name>")
For Each Elem In NodeList
msgbox Elem.text
Next
Thanks and regards
I have a problem with createTextNode method e special characters like '>', '<':
Dim xmlDoc As DOMDocument
Dim codeXML as String
Dim n As IXMLDOMNode
codeXML = '<data>value</data>'
Set n = xmlDoc.createTextNode(codeXML)
I need a result like this:
<main><data>value</data></main>
but I get
<main><data>value</data></main>
How can I solve that problem?
Thank you very much.
One way would be to create a second Document to serve as the XML parser for these XML literals. You can use LoadXML to pass the string in and get validated XML objects. You can then Import the node to the original/main DOM Document you are building.
I'm trying to include a URL to an image in an XML file, and the ampersands in the URL query string are getting stripped out:
bgdoc.xpath('//Master').each do |elem|
part = elem.xpath('Part').inner_text
image = imagehash[part]
image = "" if image.blank?
elem.xpath('Image').first.content = "<![CDATA[#{image}]]>"
puts elem.xpath('Image').first.content
end
bgdoc is getting written out with the help of Builder later on. But not the individual elements, it's getting inserted all at once. That makes it a different case than a similar question posted on SO.
You should be using create_cdata to create a CDATA node and then add_child to add it to the document, just assigning a string to content will leave you with <!CDATA... in your XML and that's not very useful.
A short example should illustrate the process:
xml = '<Master><Image></Image><Image></Image></Master>'
bgdoc = Nokogiri::XML(xml)
cdata = bgdoc.create_cdata('/where?is=pan&cakes=house')
bgdoc.xpath('//Image').first.add_child(cdata)
Then, if you bgdoc.to_xml you'll get something like this:
<?xml version="1.0"?>
<Master>
<Image><![CDATA[/where?is=pan&cakes=house]]></Image>
<Image/>
</Master>
I think that's the sort of result you're looking for. However, if you just assign a string to content:
bgdoc.xpath('//Image').first.content = '<![CDATA[/where?is=pan&cakes=house]]>'
Then you get this XML:
<?xml version="1.0"?>
<Master>
<Image><![CDATA[/where?is=pan&cakes=house]]></Image>
<Image/>
</Master>
and that doesn't even have a CDATA node.
Did you try to replace the ampersand with its xml/html character code ? It should be working.
The code for the ampersand is:
&
Click here for more information about character codes.
I have got below code in VBScript:
<%
Option Explicit
#importXSLT "tcm:228-190529-2048" As expandXSLT
#importXSLT "tcm:228-642694-2048" As renderXSLT
Dim xml, currentDateTime
Set xml = getNewDomDocument()
xml.loadXML TDSE.GetListPublications(3)
expandXSLT.input = xml
Call expandXSLT.addParameter("publication", Component.Publication.Id)
expandXSLT.transform
xml.loadXML(expandXSLT.output)
'WriteOut xml.xml
currentDateTime = now
renderXSLT.input = xml
Call renderXSLT.addParameter("currentPublishedDate", currentDateTime)
renderXSLT.transform
WriteOut renderXSLT.output
Set xml = Nothing
%>
You can see there is two syntax where I am adding the XSLT parameter, the first one is working fine i.e.
expandXSLT.input = xml
Call expandXSLT.addParameter("publication", Component.Publication.Id)
expandXSLT.transform
However the new requirement was that, we need to send current date time from here to the XSLT, so I have added the same logic to send the current date & time to my XSLT, below is code added by me
currentDateTime = now
renderXSLT.input = xml
Call renderXSLT.addParameter("currentPublishedDate", currentDateTime)
renderXSLT.transform
But when I am trying to run the above code its giving below error:
Type mismatch.
(source: Call renderXSLT.addParameter("publishedDate", currentDateTime)).
Please suggest!!
Try whether converting the currentDateTime value you have to a string first to pass that string to XSLT e.g. CStr(currentDateTime).