How to XSLT-transform in-memory xml DOM tree? For example I create(with DOM) in memory XML tree and want to XSLT-transform it. I want to omit phase of serializing created DOM tree in XML and then send xml serialized document to XSLT processor(that will waist time to deserialize it again). Just directly send DOM tree as input to XSLT processor. Implementation in MSXML is preferable.
With MSXML a DOM node exposes methods transformNode (taking a DOM node with the stylesheet code as its argument and creating a string with the transformation result, see https://msdn.microsoft.com/en-us/library/ms761399%28v=vs.85%29.aspx) and transformNodeToObject (taking a DOM node with the stylesheet code as its first argument and a result object like a stream or another DOM node as the second argument, see https://msdn.microsoft.com/en-us/library/ms766561%28v=vs.85%29.aspx) so it is easy to apply XSLT to a DOM node created in memory.
Related
I am pretty new to IIB. I am creating a mediation service on IBM Integration Bus 10. First node is SOAP node and second node is an XSL transform. Complete flow of the service
XSL transform is working fine with my SOAP input when I test it in a different tool. But it fails here when I am testing from soapui. After Transform node, I am getting the output without XML tags (all values appended in single string)
I have no clue why it is happening. Any help is well appreciated.
I am getting the output without xml tags (all values appended in single string)
IIB will not assume that the output of an XSLTransform node is XML. An XSL stylesheet can output formatted text. So you must set the 'Domain' property in the 'Output message parsing' section of the XSLTransform node. Set it to XMLNSC, obviously.
First node is SOAP node and second node is xsl transform
Is there a particular reason why you have chosen to use the XSLTransform node? A Mapping node or a Compute node will perform better, and will be more maintainable than XSL (unless you are doing some genuinely complex transformations in XSL).
Maybe you have to see what is the version of the XSLT. If it is 2.0, XSL Transform Node is not supporting it. Try to rewrite it in XSLT version 1.0.
I want to try a tag not closed with xpath like this:
<figure class="img"><img class="immagine-in-linea-senza-cornice" width="16%" src="images/schema_1_fmt.jpeg" alt=""/>
I want to close the tag with a xslt transformation.
XPath does not work directly on the input document, but on an abstract, tree-like representation of the document (e.g. XDM or DOM). In this model, opening and closing tags of an element are not represented at all. Instead, an element appears as a single entity in the tree.
Therefore, manipulating < and /> is completely out of the question for languages like XPath, because the concept of opening and closing tags is simply not implemented. I would argue that this abstraction is an advantage of the models, though.
Also, XSLT transformations normally take as input XML documents. If your document has unclosed elements, it will be rejected by any application that is only prepared to process XML.
In short, fix the XML document with a language other than the combination of XSLT and XPath (see e.g. here), and think about XSLT as soon as you have well-formed XML as input.
Is it possible to create XML nodes using XPath?
Assume i got the following XML:
<data>
<someValue1></someValue2>
<someValue2></someValue2>
<someArray>
<val></val>
<val></val>
<val></val>
</someArray>
</data>
What I am trying to do is getting a node inside the XML using XPath (e.g. /data/someValue1) and setting the value of the node. This is of course easy to achieve with any language and framework supporting XML + XPath.
But when my XPath expression is pointing to a non existing node I want to somehow create this node. Even if the XPath expression is more complex (e.g. /data/someArray/val[5]).
At best this automatic node creation should be supported by some library. Is there an easy way for what I am trying to achieve? Currently I am using C++ with Qt and the QXmlQuery class.
Is it possible to create XML nodes using XPath?
No, it isn't. XPath can only select existing nodes.
If you want to create new nodes, you need XSLT or XQuery.
But even then, creating a node that satisfies a given path like /a/b/c/foo[5] is non-trivial, and not something that the languages can do automatically.
What would be a straightforward way to transform a source XML document into a destination XML document. There are only small differences between source and destination: Specifically I want to delete the first UnitIDRecord-Node within each UnitIDGroup-Node.
What would be the appropriate model for this task DOM or SAX?
What XML-library would best fit this problem (which guarantees that the source and destination only differs in the deleted nodes, no missing namespace, attributes, encoding, ...)?
I read about XSLT, could this be an option?
The XML document looks like following:
<?xml version="1.0" encoding="UTF-8"?>
<ExPostInformationRealGeneration xmlns="http://schemas.seven2one.de/EEX/TransparencyPlatform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.seven2one.de/EEX/TransparencyPlatform EEXTransparencyPlatform.xsd">
<DispatcherID>XYZ</DispatcherID>
<CreationDateTime>2012-05-22T13:57:00Z</CreationDateTime>
<MessageText>1 - Positiv - Meldung mit Quality-Tag - L000</MessageText>
<UnitIDGroup>
<UnitID>E110200-001</UnitID>
<UnitIDRecord><Quantity>16.9</Quantity><Starttime>2008-04-30T22:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord>
<UnitIDRecord><Quantity>16.6</Quantity><Starttime>2008-04-30T23:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord>
<UnitIDRecord><Quantity>16.4</Quantity><Starttime>2008-05-01T00:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord>
</UnitIDGroup>
<UnitIDGroup>
<UnitID>E110200-002</UnitID>
<UnitIDRecord><Quantity>16.9</Quantity><Starttime>2008-04-30T22:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord>
<UnitIDRecord><Quantity>16.6</Quantity><Starttime>2008-04-30T23:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord>
<UnitIDRecord><Quantity>16.4</Quantity><Starttime>2008-05-01T00:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord>
</UnitIDGroup>
<UnitIDGroup>
<UnitID>E110201-001</UnitID>
<UnitIDRecord><Quantity>7.0</Quantity><Starttime>2008-04-30T22:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord>
<UnitIDRecord><Quantity>7.1</Quantity><Starttime>2008-04-30T23:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord>
<UnitIDRecord><Quantity>7.1</Quantity><Starttime>2008-05-01T00:00:00Z</Starttime><Period>PT1H</Period><MessageText></MessageText></UnitIDRecord>
</UnitIDGroup>
<!-- other UnitIDGroup elements -->
</ExPostInformationRealGeneration>
I would consider the possibility of reading the file in as strings and writing the string out to another file if it matches your criteria. That's a 5 line program and avoids any parsing etc. It will run quickly and is simple. But, it is specific to this problem and not reusable. I offer this therefore as a suggestion not the correct solution!
I am a latecomer to XML - have to parse an XML file. Our company is using xerces already so I managed to cobble together a sample app (SAX) that displays all the data in a file. However, after parsing is complete I was expecting to be able to call the parser or some other entity that had an internal representation of the file and iterate through the fields/data.
Basically I want to be able to hand it some key or other string(s) and get back strings or collections of key/value pairs. I do not see that. It seems pretty obvious to me that that is a good thing to do. Am I missing something?
Is the DOM parsing what I want, or does that fall short too?
Xerces provides both SAX and DOM processing. SAX parsing doesn't construct a model, so once parsing is finished there is nothing to examine or iterate through. DOM processing produces a tree-structured model which gives you what you want.
Check out the beginner's sample in this page
YoLinux Tutorial on Parsing XML
If you use the XercesDOMParser, there is still no way to request a specific key value pair after the document is parsed. I ran into the same problem recently, and while iterating through the DOM tree I stored all the key value pairs in an STL map. Then you can request key value pairs from the map later in the program.