VB MS Word: Bind XML into an ordered lists? - vba

Is there any way to bind ordered lists to XML documents in MS Word?
Currently I have xml such as:
<?xml version="1.0"?>
<myvars>
<name>foo</name>
</myvars>
Then I load and map it to a contentcontrol:
ActiveDocument.CustomXMLParts.Add
ActiveDocument.CustomXMLParts(5).Load ("c:\test.xml")
Dim strXPath1 As String
strXPath1 = "/myvars/name"
ActiveDocument.ContentControls(1).XMLMapping.SetMapping strXPath1
However this is only useful for single texts. Is there anyway to map xml enteries to ordered lists? For example:
<?xml version="1.0"?>
<myvars>
<person>
<name>foo</name>
<alias>bar</alias>
<alias>chew</alias>
</person>
<person>
<name>alpha</name>
<alias>bravo</alias>
<alias>charlie</alias>
</person>
</myvars>
mapped into the word document so that it shows up as ordered lists:
1. foo
a. bar
b. chew
2. alpha
a. bravo
b. charlie

Basically, the answer is you cannot. You can only map simple text and combo box type content controls to XML.

Related

Is there any existing service in HotDocs tools to receive data from an external source to prepare a document?

HotDocs is a tool to generate documents and basically it carries 2 things. First is temple and second is answer file. Template carries variables and data to those variables are pushed through answer file.
Generally answer file is page where is it asks for data and further it generates a document.
Now our requirement is - instead of passing variable's values through answer file, I need to send through a API built using PHP which provides data in JSON format.
IS there any exiting service in HotDocs to serve this kind requests?. I can change the data from JSON to XML if required.
At the moment there is no off the shelf converter from JSON to HotDocs Answer XML however, at HotDocs we do this all the time. If you produce either JSON or XML from your application the data will need to be transformed into the HotDocs answer XML format - e.g.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AnswerSet title="Demo Answers" version="1.1">
<Answer name="Employee Name">
<TextValue>Graham Penman</TextValue>
</Answer>
<Answer name="Job Duty">
<RptValue>
<TextValue>make tea</TextValue>
<TextValue>make coffee</TextValue>
<TextValue>make some cake</TextValue>
</RptValue>
</Answer>
<Answer name="Annual Salary">
<NumValue>12.0000000</NumValue>
</Answer>
<Answer name="Contract Date">
<DateValue>10/10/2016</DateValue>
</Answer>
<Answer name="Paid Seminar Days">
<TFValue>false</TFValue>
</Answer>
</AnswerSet>
There are three key things you need to know to create the answer XML: The data type of your data, the data type in HotDocs and whether the data you are passing is a list or single item.
So to build the answer XML is relatively easy.
The answer XML is essentially key value pairs being contained between the opening and closing tags:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AnswerSet title="Demo Answers" version="1.1">
...Answers go here
</AnswerSet>
We then add answers in by adding the following and specifying the variable in the template the answer corresponds to, the actual value (from your data) you want to set the answer to and also the type of data it is in the template - in the example below it is text however, the type in HotDocs are: TextValue (string), NumValue (decimal), TFValue (boolean), DateValue (DateTime) and MCValue (see later on in this answer).
<Answer name="[Variable name in template]">
<TextValue>[Value from your data]</TextValue>
</Answer>
For multiple choices specifically you can select one or more answers so the answer XML format is slightly different:
<Answer name="[Variable name in template]">
<MCValue>
<SelValue>[First selected value]</SelValue>
<SelValue>[Second selected value]</SelValue>
</MCValue>
</Answer>
If you have repeated data you want to put into the document you can use the list repeat format:
<Answer name="[Variable name in template]">
<RptValue>
<[Variable Type]>[First value]</[Variable Type]>
<[Variable Type]>[Second value]</[Variable Type]>
</RptValue>
</Answer>
Once you build this XML structure you can pass this into the assemble document method on the REST services as a string with the template to assemble the corresponding documents.

Storing XML into Postgres

I have an XML document that needs to get stored in an SQL db (Postgres).
I've already seen how that's done, but I have a question: do I just create a single table with a xml field and place the whole document there? This is a document about movies and so (movies, actors...) that has information to be later retrieved.
I've never worked with XML in databases, so I'm a little confused.
Here's an example of my XML:
<?xml version="1.0" encoding="UTF-8"?>
<cinema xmlns="movies"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="movies file:/C:/Users/Fabio/git/LAPD/movies.xsd">
<persons>
<person id="P1">
<name>Samuel L. Jackson</name>
<birth>1948-12-21</birth>
</person>
<person id="P2">
<name>Leonardo Di Caprio</name>
<birth>1974-11-11</birth>
</person>
<person id="P3">
<name>Quentin Tarantino</name>
<birth>1963-03-27</birth>
</person>
</persons>
<movies>
<movie id="M1">
<title>Pulp Fiction</title>
<length>154</length>
<year>1994</year>
<description>The lives of two mob hit men,
a boxer, a gangster's wife, and a pair
of diner bandits intertwine in four tales of violence and redemption</description>
<crew>
<director ref="P3"/>
<writer ref="P3"/>
</crew>
<cast>
<actor ref="P1"/>
</cast>
<rate>
<imdb>8.9</imdb>
<rottentomatoes>9</rottentomatoes>
<moviedb>7.8</moviedb>
<average>8.57</average>
</rate>
<numOscars>1</numOscars>
</movie>
<movie id="M2">
<title>Django Unchained</title>
<length>165</length>
<year>2012</year>
<description>With the help of a German bounty hunter,
a freed slave sets out to rescue his wife
from a brutal Mississippi plantation owner.</description>
<crew>
<director ref="P3"/>
<writer ref="P3"/>
</crew>
<cast>
<actor ref="P1"/>
<actor ref="P2"/>
</cast>
<rate>
<imdb>8.5</imdb>
<rottentomatoes>8</rottentomatoes>
<moviedb>7.4</moviedb>
<average>7.97</average>
</rate>
<numOscars>2</numOscars>
</movie>
</movies>
You can store a whole XML document as value in a single xml column or you can extract data and store it in a more or less normalized form.
Which is better, depends on all the details of your application that are unknown to us.
Here is a related answer discussing pros and cons of storing document types vs. db normalization:
Does JSONB make PostgreSQL arrays useless?
Save XML as a text column of DB so that you can also apply equality operator easily. You may find some error on insertion for " or ' so try to replace them with other characters like ~ or `, both.

dynamic payload processing in wso2 esb

I have dynamic payload coming into ESB proxy which need to be send to BAM server after parsing every individual elements (which could be nested too). This dynamic payload contains repeated complex type elements. How can I traverse it through as part of ESB sequence and give unique name for each repeated element dynamically and send it to BAM server ? e.g. Employee XML element is dynamic it can be repeated multiple times.
<Request>
<appName></appName>
<Employee>
<name></name>
<age></age>
</Employee>
<Employee>
<name></name>
<age></age>
<Qualifications>
<degree></degree>
<year></year>
<college></college>
</Qualifications>
</Employee>
<Employee>
<name></name>
<age></age>
</Employee>
</Request>
As i understood, you need to traverse through elements and send them to BAM one by one.
You can use Iterator mediator for getting the elements one by one.[1]
Then you need to use payloadFactory mediator to add a unique id. For this you can add a new element inside . You can find samples for this by searching at the same Doc site[1].
You can also refer this blog[2] to understand payloadFactory more.
[1] http://docs.wso2.org/wiki/display/ESB460/Iterate+Mediator
[2] http://madhukaudantha.blogspot.com/2013/05/wso2-esb-payload-mediator-tutorial.html

how to add a xmlnode in a particular postion of xml file using vb.net

could anybody help me to write nodes to existing xml file to a particular position using vb.net?
<xml>
<person>
<name>a</name>
</person>
<person>
<name>b</name>
</person>
<person>
<name>c</name>
</person>
<person>
<name>d</name>
</person>
</xml>
here i want to insert a node just after the node person which contains value a for the node name.
<xml>
<person>
<name>a</name>
</person>
<person>
<name>e</name>
</person>
<person>
<name>b</name>
</person>
<person>
<name>c</name>
</person>
<person>
<name>d</name>
</person>
</xml>
~|Simple Node Addition
To add a new node to an XML file, the XmlNode class provides various methods. To start, an XML file must have a root. This ensures that the file has at least one node. Before adding a new node, you must have a reference of another node. This information will allow you to decide where to position the new node.
To add a new node as a child of an existing node, the simplest position to use is to add the new node at the end of the list of nodes of the existing node. This position is supported by the XmlNode.AppendChild() method. Its syntax is:
Public Overridable Function AppendChild(ByVal newChild As XmlNode) As XmlNode
This method accepts as argument the new node that will be created. This means that you can first "build" an XmlNode object. To do this, you can use a pointer to the type of node you want to create.|~
copied from this
I got the same problem as you have, I do not think it is possible (google search have yet to yield some good results), but I will probably add an attribute to my nodes and then sort it using Jon Skeet's suggestion.

Import Xml nodes as Xml column with SSIS

I'm trying to use the Xml Source to shred an XML source file however I do not want the entire document shredded into tables. Rather I want to import the xml Nodes into rows of Xml.
a simplified example would be to import the document below into a table called "people" with a column called "person" of type "xml". When looking at the XmlSource --- it seem that it suited to shredding the source xml, into multiple records --- not quite what I'm looking for.
Any suggestions?
<people>
<person>
<name>
<first>Fred</first>
<last>Flintstone</last>
</name>
<address>
<line1>123 Bedrock Way</line>
<city>Drumheller</city>
</address>
</person>
<person>
<!-- more of the same -->
</person>
</people>
I didn't think that SSIS 2005 supported the XML datatype at all. I suppose it "supports" it as DT_NTEXT.
In any case, you can't use the XML Source for this purpose. You would have to write your own. That's not actually as hard as it sounds. Base it on the examples in Books Online. The processing would consist of moving to the first child node, then calling XmlReader.ReadSubTree to return a new XmlReader over just the next <person/> element. Then use your favorite XML API to read the entire <person/>, convert the resulting XML to a string, and pass it along down the pipeline. Repeat for all <person/> nodes.
Could you perhaps change your xml output so that the content of person is seen as a string? Use escape chars for the <>.
You could use a script task to parse it as well, I'd imagine.