WFS GetFeature output from ArcGIS cannot be parsed with any ol.format.* - openlayers-3

A simple ol.format.ogc.filter.bbox works with no problem using Geoserver, and I can parse the output xml as follows:
features = new ol.format.GML3().readFeatures(result);
However; when using the same filter with ArcGIS the output xml cannot be parsed. The results returned by the map server are correct, but the code above parses only the first feature returned. I tried using new ol.format.GML2 which parses the right amount of features but with no geometry, so I think it is not the case. There is a clear difference in the output xmls (see below).
How can I parse the second xml (returned by ArcGIS) using OpenLayers 3? Is there a way to change the output xml in ArcGIS?
Geoserver:
<?xml version="1.0" encoding="UTF-8"?>
<wfs:FeatureCollection numberOfFeatures="2" timeStamp="2016-09-02T15:19:25.157Z" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:ows="http://www.opengis.net/ows" xmlns:rkms="http://rkms" xmlns:wfs="http://www.opengis.net/wfs" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://mapserver/geoserver/wfs?service=WFS&version=1.1.0&request=DescribeFeatureType&typeName=rkms%3AMyLayer http://www.opengis.net/wfs http://mapserver/geoserver/schemas/wfs/1.1.0/wfs.xsd">
<gml:boundedBy>
<gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#3857">
<gml:lowerCorner>6290152.654765377 2551363.9791194764</gml:lowerCorner>
<gml:upperCorner>6290408.655102356 2551457.2361871097</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<gml:featureMembers>
<rkms:MyLayer gml:id="MyLayer.4727">
<gml:boundedBy>
<gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#3857">
<gml:lowerCorner>6290152.654765377 2551363.9791194764</gml:lowerCorner>
<gml:upperCorner>6290152.654765377 2551363.9791194764</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<rkms:fid>6319.0</rkms:fid>
<rkms:uwi>FAHUD WDW-5H1</rkms:uwi>
<rkms:display_class>General#0x0048</rkms:display_class>
<rkms:label>FAHUD WDW-5H1</rkms:label>
<rkms:the_geom>
<gml:Point srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#3857">
<gml:pos>6290152.654765377 2551363.9791194764</gml:pos>
</gml:Point>
</rkms:the_geom>
<rkms:well_status>completed</rkms:well_status>
<rkms:show_type>unknown</rkms:show_type>
</rkms:MyLayer>
<rkms:MyLayer gml:id="MyLayer.21732">
<gml:boundedBy>
<gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#3857">
<gml:lowerCorner>6290408.655102356 2551457.2361871097</gml:lowerCorner>
<gml:upperCorner>6290408.655102356 2551457.2361871097</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<rkms:fid>23325.0</rkms:fid>
<rkms:uwi>FAHUD WDW-7H1</rkms:uwi>
<rkms:display_class>General#0x0048</rkms:display_class>
<rkms:label>FAHUD WDW-7H1</rkms:label>
<rkms:the_geom>
<gml:Point srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#3857">
<gml:pos>6290408.655102356 2551457.2361871097</gml:pos>
</gml:Point>
</rkms:the_geom>
<rkms:well_status>producing</rkms:well_status>
<rkms:show_type>unknown</rkms:show_type>
</rkms:MyLayer>
</gml:featureMembers>
ArcGIS:
<?xml version="1.0" encoding="UTF-8"?>
<wfs:FeatureCollection xmlns:MyLayer="http://mapserver/arcgis/services/MyLayer/MapServer/WFSServer" xmlns:gml="http://www.opengis.net/gml" xmlns:wfs="http://www.opengis.net/wfs" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mapserver/arcgis/services/MyLayer/MapServer/WFSServer http://mapserver/arcgis/services/MyLayer/MapServer/WFSServer?request=DescribeFeatureType%26version=1.1.0%26typename=WellHole http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd http://www.opengis.net/gml http://schemas.opengis.net/gml/3.1.1/base/gml.xsd">
<gml:boundedBy>
<gml:Envelope srsName="EPSG:3857">
<gml:lowerCorner>6280561.8275626749 2548148.676770444</gml:lowerCorner>
<gml:upperCorner>6289533.3190469407 2559799.8122104518</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<gml:featureMember>
<MyLayer:WellHole gml:id="F662__369">
<MyLayer:OBJECTID>369</MyLayer:OBJECTID>
<MyLayer:Well_Number>0</MyLayer:Well_Number>
<MyLayer:Hole_Number>0</MyLayer:Hole_Number>
<MyLayer:SHAPE>
<gml:Point>
<gml:pos>6288892.4079840938 2550358.0037752441</gml:pos>
</gml:Point>
</MyLayer:SHAPE>
</MyLayer:WellHole>
</gml:featureMember>
<gml:featureMember>
<MyLayer:WellHole gml:id="F662__400">
<MyLayer:OBJECTID>400</MyLayer:OBJECTID>
<MyLayer:Well_Number>0</MyLayer:Well_Number>
<MyLayer:Hole_Number>0</MyLayer:Hole_Number>
<MyLayer:SHAPE>
<gml:Point>
<gml:pos>6288797.9203164754 2550567.9331951309</gml:pos>
</gml:Point>
</MyLayer:SHAPE>
</MyLayer:WellHole>
</gml:featureMember>
</wfs:FeatureCollection>

Use ol.format.WFS that should work.

Related

XSLT: how to pass different prefix values for Node and its feilds

I have a requirement where Nodes have a different prefix value where as fields under them has a different prefix, how to achieve this using XSLT. I have attached sample input and expected its output. Can you please advise.
I am expecting nodes have prebix "cac" and its fields as "cbc" and also replace namespace ns2 with r1 prefix.
Input:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:StandardBusinessDoc xmlns:ns0="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader">
<ns1:Invoice xmlns:ns1="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<ns1:CustomizationID>urn:cen.eu:en131:2017#compliant#urn:fdc:peppol.eu:2017:pocc:billing:3.0</ns1:CustomizationID>
<ns1:ProfileID>urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</ns1:ProfileID>
<ns1:ID>80160238</ns1:ID>
<ns1:BuyerReference>202208_604</ns1:BuyerReference>
<ns1:BillingReference>
<ns1:InvoiceDocumentReference>
<ns1:ID>test</ns1:ID>
<ns1:IssueDate>2022-09-28</ns1:IssueDate>
</ns1:InvoiceDocumentReference>
</ns1:BillingReference>
<ns1:AdditionalDocumentReference>
<ns1:ID>06AB87FD6E1E1EED96F1653A13ADC23</ns1:ID>
<ns1:DocumentDescription>SupplierUID</ns1:DocumentDescription>
</ns1:AdditionalDocumentReference>
<ns1:AdditionalDocumentReference>
<ns1:ID>2M</ns1:ID>
<ns1:DocumentDescription>Series</ns1:DocumentDescription>
</ns1:AdditionalDocumentReference>
<ns2:Classification xmlns:ns2="rl:rl-einvoicing">
<ns2:Line>
<ns2:ID>000010</ns2:ID>
<ns2:VatCategory>
<ns2:VatRate>24</ns2:VatRate>
<ns2:IncomeClassification>
<ns2:Category>category1_2</ns2:Category>
<ns2:Type>E3_561_005</ns2:Type>
<ns2:Amount>112.33</ns2:Amount>
</ns2:IncomeClassification>
</ns2:VatCategory>
</ns2:Line>
</ns2:Classification>
</ns0:StandardBusinessDoc>
Expected Output:
<?xml-model href="http://www.unece.org/fileadmin/DAM/cefact/namespaces/StandardBusinessDocumentHeader/StandardBusinessDocumentHeader.xsd" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<StandardBusinessDoc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader http://www.unece.org/fileadmin/DAM/cefact/namespaces/StandardBusinessDocumentHeader/StandardBusinessDocumentHeader.xsd" xmlns:rl="rl:rl-einvoicing" xmlns="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader">
<Invoice xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<cbc:CustomizationID>urn:cen.eu:en131:2017#compliant#urn:fdc:peppol.eu:2017:pocc:billing:3.0</cbc:CustomizationID>
<cbc:ProfileID>urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</cbc:ProfileID>
<cbc:ID>80160238</cbc:ID>
<cbc:BuyerReference>202208_604</cbc:BuyerReference>
<cac:BillingReference>
<cac:InvoiceDocumentReference>
<cbc:ID>test</cbc:ID>
<cbc:IssueDate>2022-09-28</cbc:IssueDate>
</cac:InvoiceDocumentReference>
</cac:BillingReference>
<cac:AdditionalDocumentReference>
<cbc:ID>06AB87FD6E1E1EED96F1653A13ADC23</cbc:ID>
<cbc:DocumentDescription>SupplierUID</cbc:DocumentDescription>
</cac:AdditionalDocumentReference>
<cac:AdditionalDocumentReference>
<cbc:ID>2Μ</cbc:ID>
<cbc:DocumentDescription>Series</cbc:DocumentDescription>
</cac:AdditionalDocumentReference>
<rl:Classification>
<rl:Line>
<rl:ID>000010</rl:ID>
<rl:VatCategory>
<rl:VatRate>24</rl:VatRate>
<rl:IncomeClassification>
<rl:Category>category1_2</rl:Category>
<rl:Type>E3_561_005</rl:Type>
<rl:Amount>112.33</rl:Amount>
</rl:IncomeClassification>
</rl:VatCategory>
</rl:Line>
</rl:Classification>
</StandardBusinessDoc>

My F# code cannot read XML using XSD template

I want to parse data from my bank account in F# that are provided in XML. I have an XSD schema of a statement.
My code reads the schema but it is not able to read the structure. I see the content in XML in data.XElement, however, data.AccountStatement property does not exist. The code goes to None option and then the application crashes. Do you have any idea why the code loads the schema but cannot work with data in XML?
open FSharp.Data
let TestAddress = "TESTADDRESS"
let dateRegex = #"\d{1,2}[.]\d{1,2}[.]\d{4}";
type BankTransactionList = XmlProvider<Schema="Schemas/IBSchema.xsd">
let data = BankTransactionList.Parse(Http.RequestString(TestAddress))
[<EntryPoint>]
let main argv =
let AccountStatement =
match data.AccountStatement with
| Some v -> Some v
| None -> None //code goes here
let TransactionList =
match AccountStatement.Value.TransactionList with //and crashes here
| Some v -> Some v
| None -> None
for transaction in TransactionList.Value.Transactions do
printf "%s" transaction.Column22.Value
0 // return an integer exit code
I am developing in .Net Core 2.1. You can see the anonymized example of XML data below.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AccountStatement>
<Info>
<accountId>X</accountId>
<bankId>X</bankId>
<currency>CZK</currency>
<iban>X</iban>
<bic>X</bic>
<openingBalance>X</openingBalance>
<closingBalance>X</closingBalance>
<dateStart>X</dateStart>
<dateEnd>X</dateEnd>
<idFrom>X</idFrom>
<idTo>16663326563</idTo>
</Info>
<TransactionList>
<Transaction>
<column_22 name="ID pohybu" id="22">0</column_22>
<column_0 name="Datum" id="0">2018-08-25+02:00</column_0>
<column_1 name="Objem" id="1">0</column_1>
<column_14 name="Měna" id="14">CZK</column_14>
<column_5 name="VS" id="5">1023</column_5>
<column_16 name="Zpráva pro příjemce" id="16">Message</column_16>
<column_8 name="Typ" id="8">Platba kartou</column_8>
<column_9 name="Provedl" id="9">Pešík, Jiří</column_9>
<column_17 name="ID pokynu" id="17">0</column_17>
</Transaction>
</TransactionList>
</AccountStatement>
I think the issue is that the schema requires the namespace: "http://www.fio.cz/IBSchema".
Adding the namespace in the document should solve the issue:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AccountStatement xmlns="http://www.fio.cz/IBSchema">
<Info>
<accountId>X</accountId>
<bankId>X</bankId>
<currency>CZK</currency>
<iban>X</iban>
<bic>X</bic>
<openingBalance>0</openingBalance>
<closingBalance>0</closingBalance>
<dateStart>2000-01-01</dateStart>
<dateEnd>2001-01-01</dateEnd>
<idFrom>0</idFrom>
<idTo>16663326563</idTo>
</Info>
<TransactionList>
<Transaction>
<column_22 name="ID pohybu" id="22">0</column_22>
<column_0 name="Datum" id="0">2018-08-25+02:00</column_0>
<column_1 name="Objem" id="1">0</column_1>
<column_14 name="Měna" id="14">CZK</column_14>
<column_5 name="VS" id="5">1023</column_5>
<column_16 name="Zpráva pro příjemce" id="16">Message</column_16>
<column_8 name="Typ" id="8">Platba kartou</column_8>
<column_9 name="Provedl" id="9">Pešík, Jiří</column_9>
<column_17 name="ID pokynu" id="17">0</column_17>
</Transaction>
</TransactionList>
</AccountStatement>
I hope your bank is not producing documents lacking the namespace and a schema requiring it.

Xml parsing in rails

I have this XML data:
<?xml version="1.0" encoding="UTF-8"?>
<responseParam>
<RESULT>-1</RESULT>
<ERROR_CODE>509</ERROR_CODE>
</responseParam>
How can I fetch the value of error code only?
I have tried this :
result = Net::HTTP.get(URI.parse(otpUrl))
data = Hash.from_xml(result)
puts "#{data['ERROR_CODE']}"
puts data[:ERROR_CODE]
printing only "data" gives me the whole hash. I am not able to get only the value of ERROR_CODE.
Any help ?
you can use Nokigiri here.
suppose this is your error.xml
<?xml version="1.0" encoding="UTF-8"?>
<responseParam>
<RESULT>-1</RESULT>
<ERROR_CODE>509</ERROR_CODE>
</responseParam>
you can do something like:-
#doc = Nokogiri::XML(File.open("error.xml"))
#doc.xpath("//ERROR_CODE")
will give you something like:-
# => ["<ERROR_CODE>509</ERROR_CODE>]"
The Node methods xpath and css actually return a NodeSet, which acts very much like an array, and contains matching nodes from the document.

Read XML file with Nokogiri

I currently have an XML file that is reading correctly except for one part. It is an item list and sometimes one item has multiple barcodes. In my code it only pulls out the first. How can I iterate over multiple barcodes. Please see code below:
def self.pos_import(xml)
Plu.transaction do
Plu.delete_all
xml.xpath('//Item').each do |xml|
plu_import = Plu.new
plu_import.update_pointer = xml.at('Update_Type').content
plu_import.plu = xml.at('item_no').content
plu_import.dept = xml.at('department').content
plu_import.item_description = xml.at('item_description').content
plu_import.price = xml.at('item_price').content
plu_import.barcodes = xml.at('UPC_Code').content
plu_import.sync_date = Time.now
plu_import.save!
end
end
My test XML file looks like this:
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<items>
<Item>
<Update_Type>2</Update_Type>
<item_no>0000005110</item_no>
<department>2</department>
<item_description>DISC-ALCOHOL PAD STERIL 200CT</item_description>
<item_price>7.99</item_price>
<taxable>No</taxable>
<Barcode>
<UPC_Code>0000005110</UPC_Code>
<UPC_Code>1234567890</UPC_Code>
</Barcode>
</Item>
</Items>
Any ideas how to pull both UPC_Code fields out and write them to my database?
.at will always return a single element. To get an array of elements use xpath like you do to get the list of Item elements.
plu_import.barcodes = xml.xpath('//UPC_Code').map(&:content)
Thanks for all the great tips. It definitely led me in the right direction. The way that I got it to work was just adding a period before the double //.
plu_import.barcodes = xml.xpath('.//UPC_Code').map(&:content)

PHP Error: DOMDocument::loadXML() [domdocument.loadxml]: Start tag expected, '<' not found in Entity

Please check this bellow program.
::Program::
<?php
$xml='
<books>
<book>
<name>Java complete reference</name>
<cost>256</cost>
</book>
<book>
<name>Head First PHP and Mysql</name>
<cost>389</cost>
</book>
</books>';
$dom=new DOMDocument();
$dom->loadXML($xml);
foreach ($dom->getElementsByTagName('book') as $book)
{
foreach($book->getElementsByTagName('name') as $name)
{
$names[]=$name->nodeValue;
}
foreach($book->getElementsByTagName('cost') as $cost)
{
$costs[]=$cost->nodeValue;
}
}
print_r($names);
?>
It is shows error:
DOMDocument::loadXML() [domdocument.loadxml]: Start tag expected, '<' not found in Entity
Is this correct way to do this?
If it is correct, Is there any way to get the proper result without changing this < to < and > to >?
You should not be using character entities for < and > on things that are actually XML tags in the string that represents your XML. It should be this:
$xml='
<books>
<book>
...
Do that and the warning goes away.
You only need to use character entities for < and > when they are part of the actual data rather than delimiting an XML tag.
DOMDocument expects the string to be VALID xml.
Your string isn't a valid XML string. You should just use < in stead of <
Why would you have the htmlentities in that string?
Aren't you supposed to start with something like this
<?xml version="1.0" encoding="UTF-8" ?>
to create valid XML? That might be the missing start tag your error is talking about.
Thank you all. Just now i have tried with the method "html_entity_decode()". It is worked for me for this example.
::Code::
<?php
$xml='
<books>
<book>
<name>Java complete reference</name>
<cost>256</cost>
</book>
<book>
<name>Head First PHP and Mysql</name>
<cost>389</cost>
</book>
</books>';
$xml=html_entity_decode($xml);
$dom=new DOMDocument();
$dom->loadXML($xml);
foreach ($dom->getElementsByTagName('book') as $book)
{
foreach($book->getElementsByTagName('name') as $name)
{
$names[]=$name->nodeValue;
}
foreach($book->getElementsByTagName('cost') as $cost)
{
$costs[]=$cost->nodeValue;
}
}
print_r($names);
?>

Resources