Combine GeoServer ShapeFile with WMS Basemap on a Leaflet Client - json

I am trying to combine a WMS with an external ShapeFile uploaded to my GeoServer.
I got my WMS Map working fine with a leaflet client but I have no idea how to implement my Shapefile.
I uploaded my ShapeFile on my GeoServer in the Vectordata section.
When I do the WFS DescribeFeature request I get this answer:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:Assignment11="http://localhost:8080/geoserver/Assignment11" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" targetNamespace="http://localhost:8080/geoserver/Assignment11">
<xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://localhost:8080/geoserver/schemas/gml/2.1.2/feature.xsd"/>
<xsd:complexType name="krankenhaeuserType">
<xsd:complexContent>
<xsd:extension base="gml:AbstractFeatureType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:PointPropertyType"/>
<xsd:element maxOccurs="1" minOccurs="0" name="KH_ID" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="KH_BEZ" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="KH_TELEFON" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="KH_URL" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="KH_ART" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="TRAEGER" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="RECHTSFOR" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="BS_BEZ" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="PLZ" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="ADRESSE" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="ORT" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="DISZIPLIN" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="BETTENZAHL" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="krankenhaeuser" substitutionGroup="gml:_Feature" type="Assignment11:krankenhaeuserType"/>
</xsd:schema>
When I do the GetFeature Request with outputFormat=JSON (http://localhost:8080/geoserver/ows?service=wfs&version=1.0.0&request=GetFeature&typeName=Assignment11:krankenhaeuser&outputFormat=JSON) the answer is a complete FeatureCollection of all my features.
The thing I am missing now is that I want to add all those Features to my map as a marker for example.
Thats the main problem.
When I got that working, I want to hide all those Features and when I click the map I want the closest Feature to pop up.
This is my code so far:
<!DOCTYPE html>
<html>
<head>
<title>Assignment 11</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/leaflet#1.6.0/dist/leaflet.css" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/>
<script src="https://unpkg.com/leaflet#1.6.0/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>
</head>
<body>
<div id="mapid" style="width: 1400px; height: 700px;"></div>
<script>
var mymap = L.map('mapid').setView([51.28, 7.33], 8);
var nrwTopo = L.tileLayer.wms('http://www.wms.nrw.de/geobasis/wms_nw_dtk?', {
layers: 'WMS_NW_DTK',
format: 'image/png',
transparent: true
}).addTo(mymap);
</script>
</body>
</html>

Related

How to extract JSON value and apply looping and map to corrosponding target xml element

I am facing some issue while extracting XML value from the JSON element using XSLT in OIC, the requirement is to map those XML value to the XML element at target side by applying loop as xml value element is repeating. below are the input and output format, require your expert input-
input
{
"requestMessage":{
"contactName":"",
"primaryPhoneExt":"",
"secondaryPhoneExt":"",
"thirtyMinCallReqFlg":"<cmPCReadingDetails><readingDetailsList><readSequence>1</readSequence><readingUOM>1</readingUOM><readingTOU>1</readingTOU><readingSQI>1</readingSQI><meterRegisterTypeCode>KW</meterRegisterTypeCode><numberOfDials>6</numberOfDials><numberOfDecimals>3</numberOfDecimals><upperLimit>0</upperLimit><lowerLimit>41</lowerLimit><reading>41</reading><newReading>40</newReading><override>false</override><measurementCondition>501000</measurementCondition><measurementDescription>Regular</measurementDescription></readingDetailsList><readingDetailsList><readSequence>2</readSequence><readingUOM>1</readingUOM><readingTOU>1</readingTOU><readingSQI>1</readingSQI><meterRegisterTypeCode>KWH</meterRegisterTypeCode><numberOfDials>5</numberOfDials><numberOfDecimals>0</numberOfDecimals><upperLimit>0</upperLimit><lowerLimit>312</lowerLimit><reading>312</reading><newReading>111</newReading><override>false</override><measurementCondition>501000</measurementCondition><measurementDescription>Regular</measurementDescription></readingDetailsList></cmPCReadingDetails> ",
"contactPersonPhone":""
}
}
Target Element-:
<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.org"
targetNamespace="http://www.example.org" elementFormDefault="qualified">
<xsd:element name="thirtyMinCallReqFlg">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="cmPCReadingDetails">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="readingDetailsList" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="readSequence" type="xsd:integer"/>
<xsd:element name="readingUOM" type="xsd:integer"/>
<xsd:element name="readingTOU" type="xsd:integer"/>
<xsd:element name="readingSQI" type="xsd:integer"/>
<xsd:element name="meterRegisterTypeCode" type="xsd:string"/>
<xsd:element name="numberOfDials" type="xsd:integer"/>
<xsd:element name="numberOfDecimals" type="xsd:integer"/>
<xsd:element name="upperLimit" type="xsd:integer"/>
<xsd:element name="lowerLimit" type="xsd:integer"/>
<xsd:element name="reading" type="xsd:integer"/>
<xsd:element name="newReading" type="xsd:integer"/>
<xsd:element name="override" type="xsd:string"/>
<xsd:element name="measurementCondition" type="xsd:integer"/>
<xsd:element name="measurementDescription" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
appreciate your help.
Regards,
Nilesh Jha

Translating JSON to XML using XSD to keep whitespace

I am currently using ODI to import data that is in JSON format into an Oracle Database. I am currently using the Complex File topology, which requires me to identify the JSON file and the XSD used to translate it to XML before it maps the data into a table in the database.
I have a JSON file called sample.json:
{"DATA_DS": {"G_1": [
{
"FIELDA": "Test Data ",
"FIELDB": "12345",
"FIELDC": " ",
"FIELDD": null,
"FIELDE": " Test Data"
}
]}}
I have an XSD called sample.xsd:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://TargetNamespace.com/InboundService" xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd" targetNamespace="http://TargetNamespace.com/InboundService" elementFormDefault="qualified" nxsd:version="JSON" nxsd:encoding="UTF-8">
<xsd:element name="Root-Element">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="DATA_DS">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="G_1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FIELDA" type="xsd:string"/>
<xsd:element name="FIELDB" type="xsd:string"/>
<xsd:element name="FIELDC" type="xsd:string"/>
<xsd:element name="FIELDD" type="xsd:string"/>
<xsd:element name="FIELDE" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
When trying to translate from JSON to XML, it says that it cannot normalize.
On further investigation, I noticed that the error occurs due to FIELDC having ONLY space.
I want to be able to keep everything that is inside the double quotes, including space.
I have tried changing the XSD twice, but to no avail.
Created a simpleType and changed the type of every element inside to use the new simpleType:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://TargetNamespace.com/InboundService" xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd" targetNamespace="http://TargetNamespace.com/InboundService" elementFormDefault="qualified" nxsd:version="JSON" nxsd:encoding="UTF-8">
<xsd:element name="Root-Element">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="DATA_DS">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="G_1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FIELDA" type="stringspace"/>
<xsd:element name="FIELDB" type="stringspace"/>
<xsd:element name="FIELDC" type="stringspace"/>
<xsd:element name="FIELDD" type="stringspace"/>
<xsd:element name="FIELDE" type="stringspace"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="stringspace">
<xsd:restriction base="xsd:string">
<xsd:whiteSpace value="preserve" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
Created a simpleType inside each element and identify to preserve whitespace:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://TargetNamespace.com/InboundService" xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd" targetNamespace="http://TargetNamespace.com/InboundService" elementFormDefault="qualified" nxsd:version="JSON" nxsd:encoding="UTF-8">
<xsd:element name="Root-Element">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="DATA_DS">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="G_1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FIELDA"><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:whiteSpace value="preserve"/></xsd:restriction></xsd:simpleType></xsd:element>
<xsd:element name="FIELDB"><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:whiteSpace value="preserve"/></xsd:restriction></xsd:simpleType></xsd:element>
<xsd:element name="FIELDC"><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:whiteSpace value="preserve"/></xsd:restriction></xsd:simpleType></xsd:element>
<xsd:element name="FIELDD"><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:whiteSpace value="preserve"/></xsd:restriction></xsd:simpleType></xsd:element>
<xsd:element name="FIELDE"><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:whiteSpace value="preserve"/></xsd:restriction></xsd:simpleType></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
I am kind of new to the whole JSON,XML,XSD space, so any kind of help will be greatly appreciated.
Thanks a lot in advance! :)
You say "it says that it cannot normalize" but you don't say what "it" is.
There are many ways of converting to JSON to XML, and you haven't said which one you are using. It sounds to me as if "it" is the particular conversion tool or library that you are using, and your problem is with this tool or library.
Also, rather than paraphrasing an error message, it's best to quote it exactly. There may be people here who recognize it and can tell you exactly what it means.

Servicestack as SSRS datasource

I am trying to use servicestack as a datasource for my SSRS report. Is this possible? Right now I have a simple operation that takes a date as a parameter, looks like this in C#
[DataContract]
[Route("/Reports/SummaryBySymbol/{SummaryDate}", Summary = "Summarizes trades by symbol for a specific date.")]
public class GetTradesGroupedBySymbol : IReturn<TradesGroupedBySymbolResponse>
{
[DataMember]
[ApiMember(Name = "Summary Date",
Description = "The date for which the trades will be summarized..",
DataType = "DateTime",
IsRequired = true)]
public DateTime SummaryDate { get; set; }
}
[DataContract]
public class TradesGroupedBySymbolResponse
{
[DataMember] public IList<SymbolSummary> Result { get; set; }
}
I am trying to create a dataset in SSRS using: http://machineName:port/soap11
as the datasource.
When the dataset asks for a query, I have no idea what to enter as text and the examples I can find always cause the interface to freeze when I hit the 'next' button (so I must assume I entered something incorrectly).
Here is what I tried to enter as the query:
<Query>
<Method Namespace="http://www.company.com/types" Name="GetTradesGroupedBySymbol" />
<SoapAction>
http://www.company.com/types/GetTradesGroupedBySymbol
</SoapAction>
<Parameters>
<Parameter Name="SummaryDate" Type="XML"/>
</Parameters>
<ElementPath IgnoreNamespaces="True">
GetTradesGroupedBySymbolResponse{}/Result{}/SymbolSummary
</ElementPath>
</Query>
Here is the wsdl for the service:
<wsdl:definitions xmlns:svc="http://www.company.com/types" xmlns:tns="http://www.company.com/types" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" name="Soap11" targetNamespace="http://www.company.com/types">
<wsdl:types>
<xs:schema xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/">
<xs:element name="anyType" nillable="true" type="xs:anyType"/>
<xs:element name="anyURI" nillable="true" type="xs:anyURI"/>
<xs:element name="base64Binary" nillable="true" type="xs:base64Binary"/>
<xs:element name="boolean" nillable="true" type="xs:boolean"/>
<xs:element name="byte" nillable="true" type="xs:byte"/>
<xs:element name="dateTime" nillable="true" type="xs:dateTime"/>
<xs:element name="decimal" nillable="true" type="xs:decimal"/>
<xs:element name="double" nillable="true" type="xs:double"/>
<xs:element name="float" nillable="true" type="xs:float"/>
<xs:element name="int" nillable="true" type="xs:int"/>
<xs:element name="long" nillable="true" type="xs:long"/>
<xs:element name="QName" nillable="true" type="xs:QName"/>
<xs:element name="short" nillable="true" type="xs:short"/>
<xs:element name="string" nillable="true" type="xs:string"/>
<xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte"/>
<xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt"/>
<xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong"/>
<xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort"/>
<xs:element name="char" nillable="true" type="tns:char"/>
<xs:simpleType name="char">
<xs:restriction base="xs:int"/>
</xs:simpleType>
<xs:element name="duration" nillable="true" type="tns:duration"/>
<xs:simpleType name="duration">
<xs:restriction base="xs:duration">
<xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?"/>
<xs:minInclusive value="-P10675199DT2H48M5.4775808S"/>
<xs:maxInclusive value="P10675199DT2H48M5.4775807S"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="guid" nillable="true" type="tns:guid"/>
<xs:simpleType name="guid">
<xs:restriction base="xs:string">
<xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}"/>
</xs:restriction>
</xs:simpleType>
<xs:attribute name="FactoryType" type="xs:QName"/>
<xs:attribute name="Id" type="xs:ID"/>
<xs:attribute name="Ref" type="xs:IDREF"/>
</xs:schema>
<xs:schema xmlns:tns="http://www.company.com/types" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.company.com/types">
<xs:complexType name="GetTradesGroupedBySymbol">
<xs:sequence>
<xs:element minOccurs="0" name="SummaryDate" type="xs:dateTime"/>
</xs:sequence>
</xs:complexType>
<xs:element name="GetTradesGroupedBySymbol" nillable="true" type="tns:GetTradesGroupedBySymbol"/>
<xs:complexType name="GetTradesGroupedBySymbolResponse">
<xs:sequence>
<xs:element minOccurs="0" name="Result" nillable="true" type="tns:ArrayOfSymbolSummary"/>
</xs:sequence>
</xs:complexType>
<xs:element name="GetTradesGroupedBySymbolResponse" nillable="true" type="tns:GetTradesGroupedBySymbolResponse"/>
<xs:complexType name="ArrayOfSymbolSummary">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="SymbolSummary" nillable="true" type="tns:SymbolSummary"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfSymbolSummary" nillable="true" type="tns:ArrayOfSymbolSummary"/>
<xs:complexType name="SymbolSummary">
<xs:sequence>
<xs:element minOccurs="0" name="BuyQuantityFilled" type="xs:int"/>
<xs:element minOccurs="0" name="BuyTotalValue" type="xs:double"/>
<xs:element minOccurs="0" name="BuyWeightedAveragePrice" type="xs:double"/>
<xs:element minOccurs="0" name="CompanyName" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="SellQuantityFilled" type="xs:int"/>
<xs:element minOccurs="0" name="SellTotalValue" type="xs:double"/>
<xs:element minOccurs="0" name="SellWeightedAveragePrice" type="xs:double"/>
<xs:element minOccurs="0" name="Ticker" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="SymbolSummary" nillable="true" type="tns:SymbolSummary"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="GetTradesGroupedBySymbolIn">
<wsdl:part name="par" element="tns:GetTradesGroupedBySymbol"/>
</wsdl:message>
<wsdl:message name="GetTradesGroupedBySymbolOut">
<wsdl:part name="par" element="tns:GetTradesGroupedBySymbolResponse"/>
</wsdl:message>
<wsdl:portType name="ISyncReply">
<wsdl:operation name="GetTradesGroupedBySymbol">
<wsdl:input message="svc:GetTradesGroupedBySymbolIn"/>
<wsdl:output message="svc:GetTradesGroupedBySymbolOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_ISyncReply" type="svc:ISyncReply">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetTradesGroupedBySymbol">
<soap:operation soapAction="http://www.company.com/types/GetTradesGroupedBySymbol" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SyncReply">
<wsdl:port name="BasicHttpBinding_ISyncReply" binding="svc:BasicHttpBinding_ISyncReply">
<soap:address location="http://serverName:port/soap11"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I would expect the query to ask me for a parameter before attempting to run the soapAction (or at least error out), but the interface just locks up and I have to kill Visual Studio. Any ideas out there as to what I am doing wrong?
EDIT 1
Modified the above query and wsdl to show latest attempts to get this to work. VS still freezes.
It appears that the problem was the long running webservice response causing a connection time out in the wizard and causing the entire VS2017 environment to freeze (not optimal behavior). Once I created a dummy version of the webservice that responds with the same DTO and couple of dummy rows but that returned in less than a second, everything worked. The report was generated and I could then go in to the dataset, change the timeout to be 2 minutes and then changed the query to point back to the real web method and it worked as expected.
As a follow up detail, if you are passing a date to ServiceStack, use the 'String' data type (not XML) and ensure that the date format is yyyy-mm-dd (months and days must be padded with zeros if they are single digit values).

XML validation using XSD failing [duplicate]

This is my sample XML code:
<Address>
<StreetAddress></StreetAddress>
<OtherDestination />
<City>TORONTO</City>
</Address>
That is currently using this XSD:
<xs:element name="Address" nillable="true">
<xs:complexType>
<xs:sequence minOccurs="0">
<xs:element ref="StreetAddress" minOccurs="0"/>
<xs:element ref="OtherDestination" minOccurs="0"/>
<xs:element ref="City" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
I want to add an attribute id to Address element like this..
<Address id="first">
<StreetAddress></StreetAddress>
<OtherDestination />
<City>TORONTO</City>
</Address>
How should I change the existing XSD to fulfill my requirement?
An attribute declaration can be added within xs:complexType after the xs:sequence:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="Address">
<xs:complexType>
<xs:sequence>
<xs:element name="StreetAddress" minOccurs="0" type="xs:string"/>
<xs:element name="OtherDestination" minOccurs="0" type="xs:string"/>
<xs:element name="City" minOccurs="0" type="xs:string"/>
</xs:sequence>
<!------------------------------------------>
<!-- This is where to declare attributes: -->
<xs:attribute name="id" type="xs:string"/>
<!------------------------------------------>
</xs:complexType>
</xs:element>
</xs:schema>
The above XSD will validate your XML successfully.

xsd substitution or xlt transformation

How Do I Change this XSD using substitution to get the following outcome?
I have a XML that is being returned from my asp.net API from a Saas providor. The service comes from asp.net mvc however, I can only use asp classic, and i'm pretty limited in what i can do. I can send TSQL queries to the SQL server 2005... Other than that there's not much that can be done. So my only option for what i need (well my best current option) is this. The data returns from my asp classic page service.asp. service.asp returns the structured xml based off an XSD file that is in the same folder as my script to get the data. I'll show you what it currently returns, what the current xsd is, and what it should return, and the modifications I tried making to the XSD. Hopefully that's the info someone will need to help me as this isn't exactly my strong suite. Thanks!
Current XML Response
Currently the data returns like this:
<xmldata>
<group>
<groupid>1</groupid>
<parentid>2</parentid>
<item>133</item>
<ProductCode>blahblah</ProductCode>
<ProductName>blahblah</ProductName>
</group>
<group>
<groupid>2</groupid>
<parentid>2</parentid>
<item>134</item>
<ProductCode>blahblah</ProductCode>
<ProductName>blahblah</ProductName>
</group>
<group>
<groupid>2</groupid>
<parentid>2</parentid>
<item>313</item>
<ProductCode>blahblah</ProductCode>
<ProductName>blahblah</ProductName>
</group>
<group>
<groupid>3</groupid>
<parentid>2</parentid>
<item>46</item>
<ProductCode>blahblah</ProductCode>
<ProductName>blahblah</ProductName>
</group>
</xmldata>
Current XSD File
My current XSD File is structured as follows:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="xmldata" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
<xs:element name="xmldata" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="groups">
<xs:complexType>
<xs:sequence>
<xs:element msprop:TableNameXsd="groupid" name="groupid" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
<xs:element name="ParentID" msprop:SqlDbType="Int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="groupproductlink">
<xs:complexType>
<xs:sequence>
<xs:element msprop:TableNameXsd="groupproductlink" name="ID" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
<xs:element name="groupID" msprop:SqlDbType="Int" minOccurs="0" />
<xs:element name="ProductCode" msprop:SqlDbType="Int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Products">
<xs:complexType>
<xs:sequence>
<xs:element msprop:TableNameXsd="Products" name="AutoDropShip" msprop:maxLength="1" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" msprop:SQLFrom="FROM vm.Products p INNER JOIN vm.Products_Descriptions pd ON p.ProductCode = pd.ProductCode INNER JOIN vm.PE pe ON p.ProductCode = pe.ProductCode INNER JOIN vm.Products_Memos pm ON p.ProductCode = pm.ProductCode" minOccurs="0" />
<xs:element name="productid" msprop:maxLength="30" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" minOccurs="1" />
<xs:element name="ProductCode" msprop:SQLTableAlias="p" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
<xs:element name="ProductName" msprop:maxLength="255" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
What the XML Should Be
The XML Needs to be returned in the following way (please note the attribute becoming the element)
<groups>
**<1> //<---Element=groupID**
<item>133</item>
<parentid>2</parentid>
<ProductCode>blahblah</ProductCode>
<ProductName>blahblah</ProductName>
**</1> //<---Element=groupID
<2> //<---Element=groupID**
<item>134</item>
<parentid>2</parentid>
<ProductCode>blahblah</ProductCode>
<ProductName>blahblah</ProductName>
**</2> //<---Element=groupID
<2> //<---Element=groupID**
<item>313</item>
<parentid>2</parentid>
<ProductCode>blahblah</ProductCode>
<ProductName>blahblah</ProductName>e="1">
**</2> //<---Element=groupID
<3> //<---Element=groupID**
<item>46</item>
<parentid>2</parentid>
<ProductCode>blahblah</ProductCode>
<ProductName>blahblah</ProductName>
**</3> //<---Element=groupID**
</groups>
The XSD I attempted to use and didn't get any response
I tried transforming the XSD that I listed above to the following:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="groups" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
**<xs:element name="groups" *msdata:IsDataSet="true"* msdata:UseCurrentLocale="true">**
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="groupid" *msdata:IsDataSet="true"* msdata:UseCurrentLocale="true" msprop:TableNameXsd="groupid" msprop:SqlDbType="Int" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element msprop:TableNameXsd="groupid" name="groupid" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
<xs:element name="ParentID" msprop:SqlDbType="Int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="groupproductlink">
<xs:complexType>
<xs:sequence>
<xs:element msprop:TableNameXsd="groupproductlink" name="ID" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
<xs:element name="groupID" msprop:SqlDbType="Int" minOccurs="0" />
<xs:element name="ProductCode" msprop:SqlDbType="Int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Products">
<xs:complexType>
<xs:sequence>
<xs:element msprop:TableNameXsd="Products" name="AutoDropShip" msprop:maxLength="1" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" msprop:SQLFrom="FROM vm.Products p INNER JOIN vm.Products_Descriptions pd ON p.ProductCode = pd.ProductCode INNER JOIN vm.PE pe ON p.ProductCode = pe.ProductCode INNER JOIN vm.Products_Memos pm ON p.ProductCode = pm.ProductCode" minOccurs="0" />
<xs:element name="productid" msprop:maxLength="30" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" minOccurs="1" />
<xs:element name="ProductCode" msprop:SQLTableAlias="p" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
<xs:element name="ProductName" msprop:maxLength="255" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
However,
It doesn't work currently. I think maybe I need to use a substitution group, however unfortunately it's been years since I did this and I can't remember what exactly I need to do. I truly hope someone here has some better ideas!