how to save payload of soa composite to xml file? - soa

i am working on oracle SOA project in which i want to save csv data to XML file. till now i got the payload in form of xml using Translate activity but i can only use it directly. I want to save the pay load to xml file.
i am facing following error :
<?xml version="1.0" encoding="UTF-8"?><bpelFault>
<faultType>0</faultType>
<subLanguageExecutionFault xmlns="http://docs.oasis-open.org/wsbpel/2.0/process/executable">
<part name="summary">
<summary>An error occurs while processing the XPath expression; the expression is ora:doXSLTransformForDoc("../Transformations/Transformation.xsl", $Receive_Read_InputVariable.body)</summary>
</part>
<part name="code">
<code>XPath expression failed to execute</code>
</part>
<part name="detail">
<detail>XPath expression failed to execute.
An error occurs while processing the XPath expression; the expression is ora:doXSLTransformForDoc("../Transformations/Transformation.xsl", $Receive_Read_InputVariable.body)
The XPath expression failed to execute; the reason was: javax.xml.transform.TransformerException: oramds:/deployed-composites/default/CSV_To_XML_rev1.0/Transformations/Transformation.xsl<Line 30, Column 109>: XML-22031: (Error) Variable not defined: 'oracle_empty_param'.
Check the detailed root cause described in the exception message text and verify that the XPath query is correct.
</detail>
</part>
</subLanguageExecutionFault>
</bpelFault>
I am working with oracle soa suite 12c.

It sounds like you want to convert a variable to a string. I would use an XSL transform. Input to the transform would be your newly translated variable and the output be a plain old String variable. The transform would look like this:
<xsl:template match="/">
<tns:myString>
<xsl:copy-of select="/ns0:RootElement"/>
</tns:myString>
</xsl:template>
If you wanted to, you could then write this string to the file adapter

Related

How to resolve PCDATA invalid Char value 27 [9] error when parsing XML in R [duplicate]

Currently, I'm working on a feature that involves parsing XML that we receive from another product. I decided to run some tests against some actual customer data, and it looks like the other product is allowing input from users that should be considered invalid. Anyways, I still have to try and figure out a way to parse it. We're using javax.xml.parsers.DocumentBuilder and I'm getting an error on input that looks like the following.
<xml>
...
<description>Example:Description:<THIS-IS-PART-OF-DESCRIPTION></description>
...
</xml>
As you can tell, the description has what appears to be an invalid tag inside of it (<THIS-IS-PART-OF-DESCRIPTION>). Now, this description tag is known to be a leaf tag and shouldn't have any nested tags inside of it. Regardless, this is still an issue and yields an exception on DocumentBuilder.parse(...)
I know this is invalid XML, but it's predictably invalid. Any ideas on a way to parse such input?
That "XML" is worse than invalid – it's not well-formed; see Well Formed vs Valid XML.
An informal assessment of the predictability of the transgressions does not help. That textual data is not XML. No conformant XML tools or libraries can help you process it.
Options, most desirable first:
Have the provider fix the problem on their end. Demand well-formed XML. (Technically the phrase well-formed XML is redundant but may be useful for emphasis.)
Use a tolerant markup parser to cleanup the problem ahead of parsing as XML:
Standalone: xmlstarlet has robust recovering and repair capabilities credit: RomanPerekhrest
xmlstarlet fo -o -R -H -D bad.xml 2>/dev/null
Standalone and C/C++: HTML Tidy works with XML too. Taggle is a port of TagSoup to C++.
Python: Beautiful Soup is Python-based. See notes in the Differences between parsers section. See also answers to this question for more
suggestions for dealing with not-well-formed markup in Python,
including especially lxml's recover=True option.
See also this answer for how to use codecs.EncodedFile() to cleanup illegal characters.
Java: TagSoup and JSoup focus on HTML. FilterInputStream can be used for preprocessing cleanup.
.NET:
XmlReaderSettings.CheckCharacters can
be disabled to get past illegal XML character problems.
#jdweng notes that XmlReaderSettings.ConformanceLevel can be set to
ConformanceLevel.Fragment so that XmlReader can read XML Well-Formed Parsed Entities lacking a root element.
#jdweng also reports that XmlReader.ReadToFollowing() can sometimes
be used to work-around XML syntactical issues, but note
rule-breaking warning in #3 below.
Microsoft.Language.Xml.XMLParser is said to be “error-tolerant”.
Go: Set Decoder.Strict to false as shown in this example by #chuckx.
PHP: See DOMDocument::$recover and libxml_use_internal_errors(true). See nice example here.
Ruby: Nokogiri supports “Gentle Well-Formedness”.
R: See htmlTreeParse() for fault-tolerant markup parsing in R.
Perl: See XML::Liberal, a "super liberal XML parser that parses broken XML."
Process the data as text manually using a text editor or
programmatically using character/string functions. Doing this
programmatically can range from tricky to impossible as
what appears to be
predictable often is not -- rule breaking is rarely bound by rules.
For invalid character errors, use regex to remove/replace invalid characters:
PHP: preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $s);
Ruby: string.tr("^\u{0009}\u{000a}\u{000d}\u{0020}-\u{D7FF}\u{E000‌​}-\u{FFFD}", ' ')
JavaScript: inputStr.replace(/[^\x09\x0A\x0D\x20-\xFF\x85\xA0-\uD7FF\uE000-\uFDCF\uFDE0-\uFFFD]/gm, '')
For ampersands, use regex to replace matches with &: credit: blhsin, demo
&(?!(?:#\d+|#x[0-9a-f]+|\w+);)
Note that the above regular expressions won't take comments or CDATA
sections into account.
A standard XML parser will NEVER accept invalid XML, by design.
Your only option is to pre-process the input to remove the "predictably invalid" content, or wrap it in CDATA, prior to parsing it.
The accepted answer is good advice, and contains very useful links.
I'd like to add that this, and many other cases of not-wellformed and/or DTD-invalid XML can be repaired using SGML, the ISO-standardized superset of HTML and XML. In your case, what works is to declare the bogus THIS-IS-PART-OF-DESCRIPTION element as SGML empty element and then use eg. the osx program (part of the OpenSP/OpenJade SGML package) to convert it to XML. For example, if you supply the following to osx
<!DOCTYPE xml [
<!ELEMENT xml - - ANY>
<!ELEMENT description - - ANY>
<!ELEMENT THIS-IS-PART-OF-DESCRIPTION - - EMPTY>
]>
<xml>
<description>blah blah
<THIS-IS-PART-OF-DESCRIPTION>
</description>
</xml>
it will output well-formed XML for further processing with the XML tools of your choice.
Note, however, that your example snippet has another problem in that element names starting with the letters xml or XML or Xml etc. are reserved in XML, and won't be accepted by conforming XML parsers.
IMO these cases should be solved by using JSoup.
Below is a not-really answer for this specific case, but found this on the web (thanks to inuyasha82 on Coderwall). This code bit did inspire me for another similar problem while dealing with malformed XMLs, so I share it here.
Please do not edit what is below, as it is as it on the original website.
The XML format, requires to be valid a unique root element declared in the document.
So for example a valid xml is:
<root>
<element>...</element>
<element>...</element>
</root>
But if you have a document like:
<element>...</element>
<element>...</element>
<element>...</element>
<element>...</element>
This will be considered a malformed XML, so many xml parsers just throw an Exception complaining about no root element. Etc.
In this example there is a solution on how to solve that problem and succesfully parse the malformed xml above.
Basically what we will do is to add programmatically a root element.
So first of all you have to open the resource that contains your "malformed" xml (i. e. a file):
File file = new File(pathtofile);
Then open a FileInputStream:
FileInputStream fis = new FileInputStream(file);
If we try to parse this stream with any XML library at that point we will raise the malformed document Exception.
Now we create a list of InputStream objects with three lements:
A ByteIputStream element that contains the string: <root>
Our FileInputStream
A ByteInputStream with the string: </root>
So the code is:
List<InputStream> streams =
Arrays.asList(
new ByteArrayInputStream("<root>".getBytes()),
fis,
new ByteArrayInputStream("</root>".getBytes()));
Now using a SequenceInputStream, we create a container for the List created above:
InputStream cntr =
new SequenceInputStream(Collections.enumeration(str));
Now we can use any XML Parser library, on the cntr, and it will be parsed without any problem. (Checked with Stax library);

How to replace < and > in BizTalk message?

I am new to BizTalk and I need to read some values from a SQL Server table. An example of the result set I am getting is the follow:
<SelectResponse
xmlns="http://schemas.microsoft.com/Sql/2008/05/TableOp/dbo/tableName">
<SelectResult>
<tableName xmlns="http://schemas.microsoft.com/Sql/2008/05/Types/Tables/dbo">
<Message> <item_1> item_1Value </item_1>
<item_2> item_2Value </item_2>
<item_3> item_3Value </item_3>
<item_n> item_3Value </item_n> </Message>
</tableName>
</SelectResult>
</SelectResponse>
So I get my message in BizTalk (the schema is auto-generated from SQL Adapter). What I want is the following:
<SelectResponse
xmlns="http://schemas.microsoft.com/Sql/2008/05/TableOp/dbo/tableName">
<SelectResult>
<tableName xmlns="http://schemas.microsoft.com/Sql/2008/05/Types/Tables/dbo">
<Message>
<item_1> item_1Value </item_1>
<item_2> item_2Value </item_2>
<item_3> item_3Value </item_3>
<item_n> item_3Value </item_n>
</Message>
</tableName>
</SelectResult>
</SelectResponse>
I have the new schema (for item_1, item_2, ...). Considering that <Message> can appear multiple times inside the BizTalk message, what is the easier way to get what I need and how can I do that? Thanks.
The most likely reason you are seeing this is the item Xml content is stored within another Xml structure, Message. Xml stored within Xml is escaped so this isn't an actual problem, it's the expected behavior.
You have several options including:
Use a Stored Procedure that loads and handles the item Xml as Xml and not a string in the result.
In an Orchestration, extract the item Xml, reformat to include a root element and create a new Message based on that.
The problem is how this data has been stored, not how SQL Server is returning it or how BizTalk is presenting it.

eXist - loading XSLT collection() - Exception thrown by URIResolver

Environment: eXist-db 4.2.1 , XQuery 3.1, XSLT 2.0
In eXist-db I am loading an XSLT file which includes a reference to a collection in eXist (in order to perform a search on documents found there, using a key). This reference seems to throw an error from Saxon.
Exception while transforming node: Exception thrown by URIResolver
XML docs are located at /db/apps/deheresi/data/
XSLT docs are located at /db/apps/deheresi/data/styles
In the transform function, I am passing a parameter from XQuery to the XSLT file for the absolute path to the data folder:
<param name="paramDatauri"
value="xmldb:exist:///db/apps/deheresi/data/"/>
In the XSLT file, this parameter is received and injected into a variable:
<xsl:variable name="coll"
select="collection(concat($paramDatauri,'?select=*.xml'))"/>
I've looked at possible parameters that Saxon might need, but I've not identified any that can resolve this problem.
EDIT #1: I've tried to pass an attribute in XQuery transform()
<attributes>
<attr name="paramSax" value="COLLECTION_URI_RESOLVER"/>
</attributes>
per Saxonica documentation, but I get the message
`Unable to set up transformer: Unknown configuration property`
I don't know if this is redundant/unnecessary, or if I've configured the attribute incorrectly.
EDIT #2: I've attempted to hardcode the absolute path into the XSL file:
<xsl:variable name="coll"
select="collection('xmldb:exist:///db/apps/deheresi/data/?select=*.xml')"/>
As well a relative path:
<xsl:variable name="coll"
select="collection('/db/apps/deheresi/data/?select=*.xml')"/>
Always returning the same error Exception thrown by URIResolver.
This is the first time I've tried to use a collection() function within a XSLT within eXist-db.
Many thanks.

XSLT crashes when encountering Ampersand sign

I am currently running in some trouble when trying to output a certain XML tag containing the Ampersand sign (&).
So more concrete, when I try to output the following tag. I get an error
<fullname>Ben & Jerry</fullname>
Using the following tag however runs just fine
<fullname>Ben and Jerry</fullname>
I have tried it with the following code
<xsl:template match="fullname">
<xsl:apply-templates/>
</xsl:template>
And I also tried
<xsl:template match="fullname">
<xsl:value-of-select="." disable-output-escaping="Yes"/>
</xsl:template>
Both resulted in an error. The only way how I get it to work is by using CDATA like this
<fullname><![CDATA[Ben & Jerry]]></fullname>
However, I have no control over the XML files I receive, and as such this is not a viable option. Is there something I can do within the XSLT to circumvent/fix this problem?
Thanks!
Ampersand can't appear as itself in well-formed XML. Your example should be
<fullname>Ben & Jerry</fullname>
I don't think you'll be able to get around this with any XSLT processor. You need to fix whatever generates the XML so it is well-formed.
So more concrete, when I try to output the following tag. I get an
error
<fullname>Ben & Jerry</fullname>
Actually, this isn't a tag. It's a start tag followed by some invalid content followed by an end tag.
You can't output invalid content using XSLT. If you have to output something that isn't XML, you'll need to use a non-XML tool to do it. And you're more likely to get advice on a non-XML forum.
What you haven't made clear is exactly what your input and output are. You say you are trying to output invalid XML, but you don't say what the input is.

Reference to undeclared namespace prefix when parsing MSXML

How do I solve the
Reference to undeclared namespace prefix: '%s'
problem with Microsoft's msxml implementation?
I'm using an XML feed from a government web-site that contains values i need to parse. The xml contains namespaces:
<?xml version="1.0" encoding="ISO-8859-1"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.1"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3c.org/1999/02/22-rdf-syntax-ns#rdf.xsd">
<item rdf:about="http://www.bankofcanada.ca/stats/rates_rss/STATIC_IEXE0101.xml">
<cb:statistics>
<cb:exchangeRate>
<cb:value decimals="4">1.0351</cb:value>
<cb:baseCurrency>CAD</cb:baseCurrency>
<cb:targetCurrency>USD</cb:targetCurrency>
<cb:rateType>Bank of Canada noon rate</cb:rateType>
<cb:observationPeriod frequency="daily">2011-05-09T12:15:00-04:00</cb:observationPeriod>
</cb:exchangeRate>
</cb:statistics>
</item>
</rdf:RDF>
Running the XPath query:
/rdf:RDF/item/cb:statistics/cb:exchangeRate/cb:targetCurrency
fails with the error:
Reference to undeclared namespace prefix: 'rdf'
Edit:
If i edit the original XML to remove all use of namespaces:
<?xml version="1.0" encoding="ISO-8859-1"?>
<rdf>
<item>
<statistics>
<exchangeRate>
<value decimals="4">1.0351</value>
<baseCurrency>CAD</baseCurrency>
<targetCurrency>USD</targetCurrency>
<rateType>Bank of Canada noon rate</rateType>
<observationPeriod frequency="daily">2011-05-09T12:15:00-04:00</observationPeriod>
</exchangeRate>
</statistics>
</item>
</rdf>
The query /rdf/item/statistics/exchangeRate/baseCurrency doesn't fail, and returns nodes:
<baseCurrency>CAD</baseCurrency>
How do i get Microsoft XML to work with namespaces?
Edit 2
i've tried adding SelectionNamespaces to the DOMDocument object:
doc.setProperty('SelectionNamespaces', 'xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.1"');
Now the xpath query doesn't fail, but it also returns no nodes:
nodes = doc.selectNodes('/rdf:RDF/item/cb:statistics/cb:exchangeRate/cb:targetCurrency');
See also
“undeclared reference to namespace prefix ” error
XMLReader - How to handle undeclared namespace
PRB: Specifying Fully Qualified Element Names in XPath Queries
XPath not working properly.
Using SelectionNamespaces is the correct approach, you are just missing a namespace.
Notice that your XML document explicitly sets the default namespace as follows:
xmlns="http://purl.org/rss/1.0/"
This means that any element without a prefix, such as the item element, is actually in the default namespace. So if you want to select that element with an XPath expression, you must first set an appropriate selection namespace.
To do this, you can change your call to setProperty like so:
doc.setProperty('SelectionNamespaces', 'xmlns:rss="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.1"');
Here you've assigned the default namespace from the document to the rss: prefix in your XPath expression. With that change in place, the following XPath expression should work correctly:
nodes = doc.selectNodes('/rdf:RDF/rss:item/cb:statistics/cb:exchangeRate/cb:targetCurrency');
It works because it references the item element using the correct namespace. The fact that the prefix differs between the XPath expression and the original document is immaterial. It is the namespace which the prefix is bound to that matters.
doc.setProperty('SelectionNamespaces', 'xmlns:rss="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.1"');
Dont forget to load the xsd file or schema to the xmldoc object
is the way to go
I dont have enough reputation to comment. But that bit there saved me a lot of time.
Thank you so much
If you are using XMLSerializer and see this error, it is likely that you are running into the IE bug described here:
https://stackoverflow.com/a/11399681
It took me a lot of time to realize that this was happening, so I thought it best to link these two issues.

Resources