I am using C with mini-XML 2.7, and reading a XML doc. All is fine, except that my XML has a section that looks like this:
<layer name="pattern1" width="100" height="40">
<data encoding="csv">
970,970,970,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,
1089,0,4,765,21,
0,1089,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
My code parses all the XML down here flawlessly. Then I attempt to read the CSV values, by using this:
s = mxmlGetText(node, &has_space);
But right after that, a printf() statement like this
printf("s='%s'", s);
Shows only the first line.
970,970,970,0,0,0,0,0,0,0,
I would like to read the lines below the first line, but tried to use mxmlGetText() again with no luck. And all the lines are shown by using mxmlSaveFile().
How can I get all the lines? thanks in advance.
I found a solution for this issue.
1.-Loaded the XML file using MXML_OPAQUE_CALLBACK instead MXML_TEXT_CALLBACK in the call to mxmlLoadFile().
2.-Used mxmlGetOpaque() instead mxmlGetText().
Now my code works flawlessly.
Related
I'm trying to convert a CSV to XML, which works perfectly fine when I test the map file in Visual Studio as I made sure the XSLT1.0 contains indent="yes". But for some reason when I repeat the steps in my Azure Logic App everything gets exported to one line:
<?xml version="1.0" encoding="utf-8"?><enfinity xsi:schemaLocation="http://www.fakewebsite.com/xml/ns/enfinity/7.1/bc_pricing/impex bc_pricing.xsd" major="6" minor="1" family="enfinity" branch="enterprise" build="build" xmlns="http://www.fakewebsite.com/xml/ns/enfinity/7.1/bc_pricing/impex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dt="http://www.fakewebsite.com/xml/ns/enfinity/6.5/core/impex-dt"><product-price-list id="DEMarkdown" priceType="ES_SalePrice" import-mode="UPDATE"><display-name>DE Markdown</display-name><description /><enabled>true</enabled><priority>1</priority><target-groups><customer-segments><customer-segment id="Everyone" repository-id="WhiteStuff-DE-Anonymous" /><customer-segment id="IG_RegisteredUsers" repository-id="WhiteStuff-DE-Anonymous" /></customer-segments></target-groups><product-price-list-entry sku="433493126" import-mode="REPLACE"><price-scale-table type-code="1" currency="EUR"><valid-from>2021-07-06T00:00:00+00:00</valid-from><valid-to>2099-07-13T00:00:00+00:00</valid-to><price-scale-entries><fixed-price-entry quantity="1" unit=""><value>44.95</value></fixed-price-entry></price-scale-entries></price-scale-table><price-scale-table type-code="1" currency="GBP"><valid-from>2021-07-06T00:00:00+00:00</valid-from><valid-to>2099-07-13T00:00:00+00:00</valid-to><price-scale-entries><fixed-price-entry quantity="1" unit=""><value>39.50</value></fixed-price-entry></price-scale-entries></price-scale-table></product-price-list-entry></product-price-list></enfinity>
I have 2 ways for this
WAY-1
You can use the XML Validation connector before the process which parses the content into the right format.
WAY-2
Just for viewing purposes, you can do a request-response method using Postman then use XML format in order to achieve your requirement.
For those interested, I've found a setting within the Logic App, simply select Apply XSLT output attributes and that's it, no validation needed either!
I have a postgres data-config file.
<dataConfig>
<dataSource driver=”org.postgresql.Driver” url=”jdbc:postgresql://127.0.0.1:5432/mydb” user=”user” password=”pw” />
...
</dataConfig>
But when I run it, it shows error
Data Config problem: Open quote is expected for attribute "driver" associated with an element type "dataSource".
What's the problem here. is driver information that I put wrong?
Your quotes are wrong.
” and " are not the same kind of quotes (see the different presentation). Only " is a valid double quote in an XML file (and in most/all programming contexts).
The examples in your config file seems to have been mangled by a blog or a text editor on the way.
I am attempting to use Camel's pollEnrich feature, but it is not behaving as I would like... I'm not saying it's broken, but wondering if there is a way to get the behavior I desire. That is, I have an XML (blueprint) defined route that goes something like this:
<route>
<from uri="direct:a" />
<pollEnrich uri="http:www.somewebsite.com?format=application/xml" />
<to uri="log:com.acme?level=WARN&showStreams=true" />
</route>
Now, the response normally comes back just fine (e.g., in a web browser). The problem seems to be that it is not just on one line, and for some reason Camel reads each line, sequentially into the same buffer, starting at character zero... so what we end up with is one messy line in the output from the pollEnrich. That is, the to uri="log... line prints messages like:
2015-05-26 13:55:26,379 | WARN | a.distr.topic.B] | contentEnrich |
? ? | 142 - org.apache.camel.camel-core - 2.12.0.redhat-610379 |
Exchange[ExchangePattern: InOnly, BodyType:
org.apache.camel.converter.stream.InputStreamCache, Body:
<?xml versi</ElementStatus> ]pe></Status>nd>gin>ys for this element.</Reason>>ame>
(last line vertically offset for emphasis)
I cannot seem to find a way to tell Camel that the result will be in 'prettPrint' format... Anyone know how? The documentation seems to suggest that this option does not exist--in which case, I'd consider this to be a bug... though I suppose a person could argue that a custom aggregation strategy should be used (and I'd disagree with that person, citing the simplicity of this case) :)
UPDATE#1: even using org.apache.camel.processor.aggregate.UseLatestAggregationStrategy produces the same effect. (i.e., usage as below)
<bean id="latestStrat"
class="org.apache.camel.processor.aggregate.UseLatestAggregationStrategy" />
<route>
<from uri="direct:a" />
<pollEnrich uri="http:www.somewebsite.com?format=application/xml" strategyRef="latestStrat" />
<to uri="log:com.acme?level=WARN&showStreams=true" />
</route>
...going to cross fingers and try org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy, but am guessing there is a configuration limitation with Camel always treating EOL characters as message delimiters.
UPDATE #2 - additional information:
The REST(GET) response received (tested with wget) has blank lines and null fields--but no carriage returns (^M). I've tried both the http and http4 components--same result. There is a leading <?xml version="1.0" encoding="UTF-8"?>, but no namespace/style info. I also just noticed that tab characters have been used for the pretty-ish indents. In sum, the response looks like:
<?xml version="1.0" encoding="UTF-8"?><ElementStatus>
<Flag>false</Flag>
<CODE>XYZ</CODE>
<Locale>Western</Locale>
...
(again, where the whitespace indenting has been done with tabs--AND the blank lines have a few tabs too)
...so the "answer" is that this is an apparent limitation of (or bug within) the log component's "showStreams" logic. I implemented Processor in a <bean>, routed the Exchange output from my pollEnrich to that <bean>, and logged the contents instead, and that matches exactly the output from wget.
FYI: this is camel-paxlogging (2.12.0.redhat-610379) - not sure what underlying version of camel that corresponds to, as I don't seem to have a jboss-parent-2.12.0 pom in my maven repo--which is strange, since I have other jboss-parent poms--and the red hat documentation doesn't seem to get into version composition.
FYI#2: and on a related note, when I use GroupedExchangeAggregationStrategy it does produce a List<Exchange>, BUT it behaves effectively the same as UseLatestAggregationStrategy -- i.e., 'grouped' produces a one-item List<Exchange> that only has the pollEnrich result, where 'latest' produces a standalone Exchange object that has only the pollEnrich result. Seems like an error in either GroupedExchangeAggregationStrategy or pollEnrich ... but this will likely be the topic of my next Stack-post.
All,
I try to load the FreeMarker template from database in the Smooks configuration file and use the build-ins INTERPRET to parse the string as template. However, the output is exactly the template I stored in the database.
The following is part of the Smooks configuration file:
....
<resource-config selector="hs:TravelerProfile">
<resource>org.milyn.delivery.DomModelCreator</resource>
</resource-config>
<db:executor executeOnElement="hs:TravelerProfile" datasource="StagingDS">
<db:statement>select freeMarker_template from template_lookup where agencyid='111';
</db:statement>
<db:resultSet name="mytemplate" />
</db:executor>
<ftl:freemarker applyOnElementNS="www.travel.com" applyOnElement="TravelerProfile">
<ftl:template>
< !--
<#assign templateSource = r"${mytemplate[0].freeMarker_template}">
<#assign inlineTemplate = [templateSource, "myInlineTemplate"]?interpret>
<#inlineTemplate/>
-- >
</ftl:template>
</ftl:freemarker>
.....
The template I stored in the database is like following:
<#ftl ns_prefixes={"D":"www.hhs.gov/travel"}>
<?xml version="1.0" encoding="UTF-8"?>
<po:PoHeadersInterfaceCollection xmlns:po="https://www.travel.com/xmlns/financial/po112007.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.travel.com/xmlns/financial/po112007.xsd">
<po:PoHeadersInterface>
<po:interfaceSourceCode>VendorName</po:interfaceSourceCode>
<po:poLinesInterfaceCollection>
<po:PoLinesInterface>
<po:PoDistributionsInterfaceCollection>
<po:PoDistributionsInterface>
<po:destinationOrganizationId>${TravelerProfile.TravelerOfficeCode}
</po:destinationOrganizationId>
</po:PoDistributionsInterface>
</po:PoDistributionsInterfaceCollection>
</po:PoLinesInterface>
</po:poLinesInterfaceCollection>
</po:PoHeadersInterface>
</po:PoHeadersInterfaceCollection>
====================================
For some reason, the output is exactly the above template itself. "${TravelerProfile.TravelerOfficeCode}" has not been evaluated! Please help!!!
Thank you!!!
Agnes
Sine mytemplate[0].freeMarker_template returns the template source code itself (or at least I assume that), and since you are using a raw string literal (r"..."), the source code of your template will be literally ${mytemplate[0].freeMarker_template}, which is then evaluated by ?interpret to the template source code. The corrected template would be:
<#assign inlineTemplate = [mytemplate[0].freeMarker_template, "myInlineTemplate"]?interpret>
<#inlineTemplate/>
which can be also written as:
<#([mytemplate[0].freeMarker_template, "myInlineTemplate"]?interpret) />
or if you don't need the "myInlineTemplate" template name:
<#mytemplate[0].freeMarker_template?interpret />
When I try to get the attribute of URL in a test XML:
<Test> <Item URL="http://127.0.0.1?a=1&b=2"/>
</Test>
After I call: attr=xmlGetProp(cur, BAD_CAST "URL");
The libxml2 give a message: Entity: line 1: parser error : EntityRef: expecting ';'
and return value of attr is "http://127.0.0.1?a=1=2"
How can I get the completion attribution of URL? Thanks
You cannot get the “correct” URL here because the XML file is not well-formed. the & should have been written as &. You have to ask the creator of the XML file to create a syntactically valid, well-formed XML file.
XML is not created by just putting strings together, they also have to be encoded properly.