Google Distance Matrix returning wrong location based on Zip Code - google-distancematrix-api

I'm sending the following to get the distance between two zip codes via MS Access.
https://maps.googleapis.com/maps/api/distancematrix/xml?origins=74104&destinations=30333&units=imperial&key=******
The response however is giving me the wrong location:
<DistanceMatrixResponse>
<status>OK</status>
<origin_address>74210 Doussard, France</origin_address>
<destination_address>Atlanta, GA 30333, USA</destination_address>
<row>
<element>
<status>ZERO_RESULTS</status>
</element>
</row>
</DistanceMatrixResponse>
It continually mixes up 74104 (Tulsa, OK) with 74210 (Doussard, France)
What could be causing that?

Related

BizTalk Mapping Fields to a Sequence

I am getting my hands on BizTalk and VS. My input schema looks something similar to this.
<root>
<order>
<orderid>
<orderdate>
...
...
and the output schema
<order>
<header:sequence>
<element name="orderid">
<element name="orderdate">
...
...
</header:sequence>
In short, in output, the header is a sequence of complex types and individual nodes in the source are enumerated as the sequence in the output.
How do we solve this in Visual Studio?
What you need to do is having a looping functoid that goes from each of the element being mapped and to the repeating destination element. And then two links from the source elements the first that is a standard link Copy text value, the second that goes to the name attribute, for which you change the link to Copy name.
Input
<root>
<order>
<orderid>1234567890</orderid>
<orderdate>2020-01-28</orderdate>
</order>
</root>
Output
<order>
<header>
<element name="orderid">1234567890</element>
<element name="orderdate">2020-01-28</element>
</header>
</order>
Note: You can change the order of what is output by using the reorder inputs in the Configure Looping Functoid.

XMLPath Query for nested XML fragment

I'm trying to write a xpath query to pull data from an xml document. Unfortunately the document has a xml fragment embedded in it that seems to have lost its encoding (< has become &lt > has become &gt etc).
An example of the xml doc is:
<OrderData xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Id>1</Id>
<RawData><?xml version="1.0" encoding="UTF-16"?>
<Data xmlns="nnn-mmm-com">
<Order Action="Remove" >
<Instrument InstID="1"></Order><
/Data>
</RawData>
</OrderData>
I'm trying to extract the following values:
Id
Action
InstID
Getting the Id is no problem, but drilling into the fragment inside RawData is proving beyond me. Any pointers gratefully received
(I'm planning to execute the xpath query in Hive using Hive-XML-SerDe which is xpath 1.0)
Thanks
With XPath 3.1 you can parse the embedded XML document and turn it into a node tree, which you can then process using path expressions. So:
/OrderData/RawData/parse-xml(.)/*:Data/*:Instrument/#InstID
should get what you want.
You didn't say what version of XPath your library supports, which usually means that it only supports 1.0, so you may need to find a different library.

XSLT Sort parent node based on specific attribute of a child

first post ever, have done lots of searching but cannot find an answer specific enough or more importantly, relevant enough. Note that I am a business analyst, not a developer, so I may be missing some understanding here.
We produce XML that we then process to produce a report. Where data can be represented by a table, the XML contains details for the table title (ELEMENT_HEADING), table header row (PROMPTS), then repeating nodes representing the rows (DATA) and columns (VALUES).
The problem I am facing is I need to sort the DATA node based on a text value of the node where the node has a specific attribute value.
In the sample XML provided below, I need to sort the DATA node based on the VALUE text value for the attribute #pic='TRORGPCNT' in ascending order i.e the DATA node with TRORGPCNT of 10 should appear before the DATA node with 90. Then when the report is produced the table rows are in ascending percentage order.
I hope have explained myself clearly enough :)
Any tips on how I might accomplish this?
Sample XML:
<PROPOSAL_ELEMENT multi="Y" pec="TEACHRESP" elem_mandatory="N" elem_visible="Y">
<ELEMENT_HEADING pec="TEACHRESP">Teaching Responsibility</ELEMENT_HEADING>
<PROMPTS>
<PROMPT pic="TRORGUN" item_mandatory="Y" item_visible="Y">Faculty or School with teaching responsibility</PROMPT>
<PROMPT pic="TRORGPCNT" item_mandatory="Y" item_visible="Y">Teaching responsibility %</PROMPT>
</PROMPTS>
<DATA elem_mandatory="N" elem_visible="Y" delete_ind="N">
<VALUES>
<VALUE pic="TRORGUN" item_mandatory="Y" item_visible="Y" item_description="FACULTY OF NURSING AND HEALTH" display_in_summary_tab="Y" summary_order="">FACULTY OF NURSING AND HEALTH</VALUE>
<VALUE pic="TRORGPCNT" item_mandatory="Y" item_visible="Y" item_description="" display_in_summary_tab="Y" summary_order="">90</VALUE>
</VALUES>
</DATA>
<DATA elem_mandatory="N" elem_visible="Y" delete_ind="N">
<VALUES>
<VALUE pic="TRORGUN" item_mandatory="Y" item_visible="Y" item_description="FACULTY OF ARTS" display_in_summary_tab="Y" summary_order="">FACULTY OF ARTS</VALUE>
<VALUE pic="TRORGPCNT" item_mandatory="Y" item_visible="Y" item_description="" display_in_summary_tab="Y" summary_order="">10</VALUE>
</VALUES>
</DATA>
Sorting in XSLT is accomplished using the xsl:sort instruction, which must appear as the first child of the for-each or apply-templates that selects the nodes you want to sort. If you're selecting the set of DATA element nodes then an appropriate sorting instruction would be
<xsl:sort select="VALUES/VALUE[#pic='TRORGPCNT']"
data-type="number" />

How to get XmlInputParser work with self-closing XML tags?

I am trying to load XML files from SE data dump* into HDFS using MapReduce. These XML files consist of a number of <row> elements (enclosed in a top-level "category"), like so:
<badges>
<row Id="1" UserId="1" Name="Organizer" Date="2009-07-15T06:51:46.370" />
<row Id="2" UserId="3" Name="Organizer" Date="2009-07-15T06:51:46.387" />
<row Id="4" UserId="1" Name="Autobiographer" Date="2009-07-15T06:51:46.447" />
...
</badges>
I want each "row" to be processed by a separate map() function, and have configured org.apache.mahout.classifier.bayes.XmlInputFormat's start and end tags as below:
Configuration config = new Configuration();
config.set(XmlInputFormat.START_TAG_KEY, "<row>");
config.set(XmlInputFormat.END_TAG_KEY, "</row>");
However, this fails to parse the XML file, because the <row> element is self-closing. How do I get this to work, without artificially "closing" the self-closing tags?
Linking to SE blog rather than directly to the data dump, to prevent dead link in case location changes in future.
This is a somewhat ugly hack. Change the START_TAG_KEY and END_TAG_KEY as below:
config.set(XmlInputFormat.START_TAG_KEY, "<row");
config.set(XmlInputFormat.END_TAG_KEY, "/>");
The "keys" are being used like delimiters, and accept any string, rather than just XML tags. Not a "clean" solution, and may stop working on future implementations, but it gets the work done now.
Note: I figured it out while I was midway through posting the question. This seems rather obvious in hindsight, but I decided to go ahead with the post anyway, so that someone may find it useful in future.

XPath with MSXML, "scope" of XPath-expressions

i have an understanding-problem using Microsoft XML Core Services 6.0 (MSXML) with XPath-expressions.
I´ve broken down the problem to the most simple case. So let´s take the following XML-File:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<element name="E1A1">
<subEle value="1a"/>
<subEle value="1b"/>
<subEle value="1c"/>
</element>
<element name="E2A1">
<subEle value="2a"/>
<subEle value="2b"/>
<subEle value="3b"/>
</element>
<element name="E3A1">
<subEle value="3a"/>
<subEle value="3b"/>
<subEle value="3c"/>
</element>
</root>
I want to get the "value"-attribues per "element". I will use pseudo-code to describe
my problem and i will focus on the important things, so i will not write how i initialize
the Msxml2.DOMDocument variable etc. .
First, i get all "element"-nodes that have a name-attribute:
oNodeList = oDom.selectNodes("//element[#name]")
The result of the selectNodes-statement is a nodelist, where i access the items node by node
in a for-loop. In this loop, i execute another selectNodes-statement, that gives me (at least i thought so)
the "subEle"s for each "element":
for i from 1 to oNodeList.length
oNodeMain = oNodeList.nextNode()
oNodeResList = oNodeMain.selectNodes("//subEle")
msgInfo("n items", oNodeResList.length)
endFor
And here comes the problem: the selectNodes-statement in the loops seems to have ALL "subEle"s
in scope; the messagebox pops up three times, telling me the length of the nodelist is 9.
I would have expected that it pops up 3 times, telling me each time that the nodelist has a length of 3 (because
every "element" has exactly 3 "subEle"s), since i´m doing the selectNodes-statement on "oNodeMain",
which gets the nextNode in each loop. Maybe i just need to modify XPath-expression in the loop and
don´t use the "//", because it works then, but i have no idea why.
The program i use for this is Paradox 11 and i use MSXML by OLE.
Is this behaviour "normal", where is my misunderstanding? Any suggestions on how to achieve what i´m
trying are welcome.
Don't use an absolute path starting with /, instead use a relative path i.e. oNodeMain.selectNodes("subEle") selects all subEle child elements of oNodeMain and oNodeMain.selectNodes(".//subEle") selects all descendant subEle elements of oNodeMain.
Your path starting with // searches from the root node (also called document node).

Resources