I have a very large xml field inside of a SQL Database that I have to edit regularly. I wrote the following Query to change that code which was easy following the xml path to get to what needed changed.
However I found more things further down in SQL that needs altered and I can not figure out the xml path to edit to make that change.
I've been utilizing the following Query to change just the username
DECLARE #config_xml2 xml
select #config_xml2 = configuration_xml from tblDatafeed where datafeed_name = 'DatafeedName' update tbldatafeed
set configuration_xml.modify('replace value of (//*:NetworkCredentialWrapper/#UserName)[1] with sql:variable("#LOGIN")') where datafeed_name ='DataFeedName'
Which is used to change the Username in the following:
<Tokens>
<Token name="DataFileDirectoryName" />
<Token name="DataFileName" />
<Token name="DataFileExtension" />
<Token name="LastRunTime" />
<Token name="LastFileProcessed" />
</Tokens>
<Transporter>
<transporters:WebServiceTransportActivity xmlns:transporters="clr-namespace:ArcherTech.DataFeed.Activities.Transporters;assembly=ArcherTech.DataFeed" xmlns:out="clr-namespace:ArcherTech.DataFeed;assembly=ArcherTech.DataFeed" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:compModel="clr-namespace:ArcherTech.DataFeed.ComponentModel;assembly=ArcherTech.DataFeed" xmlns:channel="clr-namespace:ArcherTech.DataFeed.Engine.Channel;assembly=ArcherTech.DataFeed" xmlns:engine="clr-namespace:ArcherTech.DataFeed.Engine;assembly=ArcherTech.DataFeed" xmlns:kernel="clr-namespace:ArcherTech.Kernel.Channel;assembly=ArcherTech.Kernel" xmlns="clr-namespace:ArcherTech.DataFeed;assembly=ArcherTech.DataFeed" xmlns:schema="clr-namespace:System.Xml.Schema;assembly=System.Xml" xmlns:xmlLinq="clr-namespace:System.Xml.Linq;assembly=System.Xml" xmlns:domain="clr-namespace:ArcherTech.Common.Domain;assembly=ArcherTech.Common" xmlns:s="clr-namespace:System;assembly=mscorlib" x:Key="transportActivity" SearchType="ReportId" Uri="Type URL Here" RecordsPerFile="100" ReportID="" UseWindowsAuth="false" IsWindowsAuthSpecific="false" WindowsAuthUserName="" WindowsAuthPassword="" WindowsAuthDomain="" ProxyName="" ProxyPort="" ProxyUsername="" ProxyPassword="" ProxyDomain="" IsProxyActive="False" ProxyOption="None" InstanceName="Type Instance Name Here" TempFileOnSuccessAction="DoNothing" TempFileOnSuccessRenameString="" TempFileOnErrorAction="DoNothing" TempFileOnErrorRenameString="" Transform="{engine:DataFeedBinding Path=Transform}" SessionContext="{engine:DataFeedBinding Path=Session}">
<transporters:ArcherWebServiceTransportActivity.Credentials>
<NetworkCredentialWrapper UserName="" />
</transporters:ArcherWebServiceTransportActivity.Credentials>
</transporters:ArcherWebServiceTransportActivity>
</Transporter>
<Iterator>
<XmlIterator>
But now I need to alter a string that a lot more complex and I am not sure my xml location is right. I have tried using //*NewSourceName1/#Calculation but it doesnt seem work:
Line of code Here I am trying to edit:
<xs:element name="NewSourceName1" type="xs:string" nillable="true" c:Name="Dashboard_Instance_Name" c:Calculation="=STATIC("MYSTRINGOFTEXTHERE")" dfm:SimpleFieldType="StaticText" />
Full xml it falls under
<Action>
<DataTransfer TargetType="Application" TargetLevel="20595ffc-afd5-4d34-babb-c8fa67c610ee" DisableValidation="true" PreValidate="false" InsertRecords="true" UpdateRecords="false" SyncAction="None" SyncFlagField="00000000-0000-0000-0000-000000000000" SyncFlagValue="00000000-0000-0000-0000-000000000000">
<Source>
<Schema><Schemas>
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.archer-tech.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dfm="http://schemas.archer-tech.com/2009/xaml/datafeed" xmlns:c="http://archertech.com/ChannelFramework/Extensions" dfm:ComplexFieldType="None">
<xs:element name="ArcherRecords" nillable="true">
<xs:complexType>
<xs:sequence>
<xs:element name="ArcherRecord" nillable="true" c:Name="ArcherRecord" dfm:ComplexFieldType="None" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" nillable="true" c:Name="Name" />
<xs:element name="Container_Type" nillable="true" c:Name="Container_Type">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" type="xs:string" nillable="true" c:Name="Item" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Path" type="xs:string" nillable="true" c:Name="Path" />
<xs:element name="Abbreviation_Unique_Key" type="xs:string" nillable="true" c:Name="Abbreviation_Unique_Key" />
<xs:element name="Container_Owner" nillable="true" c:Name="Container_Owner">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" type="xs:string" nillable="true" c:Name="Item" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Send_Upstream" nillable="true" c:Name="Send_Upstream">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" type="xs:string" nillable="true" c:Name="Item" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="NewSourceName" type="xs:string" nillable="true" c:Name="Iteration" c:Calculation="=IF(AND(HOUR(NOW())>=0,HOUR(NOW())<8), "ONE",
 IF(AND(HOUR(NOW())>=8,HOUR(NOW())<16), "TWO", "THREE"))" dfm:SimpleFieldType="CalculatedField" />
<xs:element name="NewSourceName1" type="xs:string" nillable="true" c:Name="Dashboard_Instance_Name" c:Calculation="=STATIC("MyTextHere")" dfm:SimpleFieldType="StaticText" />
<xs:element name="NewSourceName2" type="xs:string" nillable="true" c:Name="Date_Created" c:Calculation="=DATEFORMAT(TODAY(), "MM/dd/yyyy")" dfm:SimpleFieldType="CalculatedField" />
<xs:element name="NewSourceName3" type="xs:string" nillable="true" c:Name="Created_By" c:Calculation="=STATIC("Local Dashboard")" dfm:SimpleFieldType="StaticText" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</Schemas></Schema>
</Source>
Hopeful out come (Look for MYSTRINGOFTEXTHERE or if I could just edit all of =STATIC("MYSTRINGOFTEXTHERE")):
<xs:element name="NewSourceName1" type="xs:string" nillable="true" c:Name="Dashboard_Instance_Name" c:Calculation="=STATIC("MYSTRINGOFTEXTHERE")" dfm:SimpleFieldType="StaticText" />
What I tried that didn't work
DECLARE #config_xml2 xml
select #config_xml2 = configuration_xml from tblDatafeed where datafeed_name = 'DatafeedName' update tbldatafeed
set configuration_xml.modify('replace value of (//*:NewSourceName1/#Calculation)[1] with sql:variable("#CoolVariableName")') where datafeed_name ='DataFeedName'
Any help would be greatly appreciated.
The XPath expression was completely off, so I adjusted it.
In XML, there are only five built-in character entities: <, >, &, " and ' for <, >, &, " and ' respectively. I replaced them with their literals. Please try the following.
SQL
DECLARE #tbl TABLE (id int IDENTITY PRIMARY KEY, configuration_xml XML);
INSERT INTO #tbl (configuration_xml)
VALUES
(N'<Action>
<DataTransfer TargetType="Application" TargetLevel="20595ffc-afd5-4d34-babb-c8fa67c610ee" DisableValidation="true" PreValidate="false" InsertRecords="true" UpdateRecords="false" SyncAction="None" SyncFlagField="00000000-0000-0000-0000-000000000000" SyncFlagValue="00000000-0000-0000-0000-000000000000">
<Source>
<Schema>
<Schemas>
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.archer-tech.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dfm="http://schemas.archer-tech.com/2009/xaml/datafeed" xmlns:c="http://archertech.com/ChannelFramework/Extensions" dfm:ComplexFieldType="None">
<xs:element name="ArcherRecords" nillable="true">
<xs:complexType>
<xs:sequence>
<xs:element name="ArcherRecord" nillable="true" c:Name="ArcherRecord" dfm:ComplexFieldType="None" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" nillable="true" c:Name="Name" />
<xs:element name="Container_Type" nillable="true" c:Name="Container_Type">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" type="xs:string" nillable="true" c:Name="Item" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Path" type="xs:string" nillable="true" c:Name="Path" />
<xs:element name="Abbreviation_Unique_Key" type="xs:string" nillable="true" c:Name="Abbreviation_Unique_Key" />
<xs:element name="Container_Owner" nillable="true" c:Name="Container_Owner">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" type="xs:string" nillable="true" c:Name="Item" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Send_Upstream" nillable="true" c:Name="Send_Upstream">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" type="xs:string" nillable="true" c:Name="Item" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="NewSourceName" type="xs:string" nillable="true" c:Name="Iteration" c:Calculation="=IF(AND(HOUR(NOW())>=0,HOUR(NOW())<8), "ONE",
 IF(AND(HOUR(NOW())>=8,HOUR(NOW())<16), "TWO", "THREE"))" dfm:SimpleFieldType="CalculatedField" />
<xs:element name="NewSourceName1" type="xs:string" nillable="true" c:Name="Dashboard_Instance_Name" c:Calculation="=STATIC("MyTextHere")" dfm:SimpleFieldType="StaticText" />
<xs:element name="NewSourceName2" type="xs:string" nillable="true" c:Name="Date_Created" c:Calculation="=DATEFORMAT(TODAY(), "MM/dd/yyyy")" dfm:SimpleFieldType="CalculatedField" />
<xs:element name="NewSourceName3" type="xs:string" nillable="true" c:Name="Created_By" c:Calculation="=STATIC("Local Dashboard")" dfm:SimpleFieldType="StaticText" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</Schemas>
</Schema>
</Source>
</DataTransfer>
</Action>');
DECLARE #CoolVariableName varchar(30) = 'Whatever Value';
UPDATE #tbl
SET configuration_xml.modify('replace value of (//xs:element[#name="NewSourceName1"]/#*:Calculation)[1] with sql:variable("#CoolVariableName")');
SELECT * FROM #tbl;
Related
I have the following xsd where I defined a targetNamespace. I want to include the targetNamespace in the element lastModifiedDate. This xsd is incorrect:
<xs:schema version="1.0" targetNamespace="http://com.uciext.ws.hw5" xmlns:tns="http://com.uciext.ws.hw5" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="catalog">
<xs:complexType>
<xs:sequence>
<xs:element ref="lastModifiedDate"/>
<xs:element ref="description"/>
<xs:element maxOccurs="unbounded" ref="product"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="lastModifiedDate" type="xs:string"/>
<xs:element name="description" type="xs:string"/>
<xs:element name="product">
<xs:complexType>
<xs:sequence>
<xs:element ref="sku"/>
<xs:element ref="name"/>
<xs:element ref="price"/>
<xs:element ref="quantity"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sku" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="price" type="xs:double"/>
<xs:element name="quantity" type="xs:double"/>
</xs:schema>
I get the following element when I check this xsd:
Error resolving component 'lastModifiedDate'. It was detected that 'lastModifiedDate' has no namespace
How can I include the targetNamespace?
I think you need to add the namespace in every referred element...
<xs:schema version="1.0" targetNamespace="http://com.uciext.ws.hw5" xmlns:tns="http://com.uciext.ws.hw5" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="catalog">
<xs:complexType>
<xs:sequence>
<xs:element ref="tns:lastModifiedDate"/>
<xs:element ref="tns:description"/>
<xs:element maxOccurs="unbounded" ref="tns:product"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="lastModifiedDate" type="xs:string"/>
<xs:element name="description" type="xs:string"/>
<xs:element name="product">
<xs:complexType>
<xs:sequence>
<xs:element ref="tns:sku"/>
<xs:element ref="tns:name"/>
<xs:element ref="tns:price"/>
<xs:element ref="tns:quantity"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sku" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="price" type="xs:double"/>
<xs:element name="quantity" type="xs:double"/>
</xs:schema>
Hope it helps...
Regards
I have an XML file with the following content (some sensitive data replaced with 'DummyData')
<Alert>
<AlertID>23210B</AlertID>
<Title>DummyData</Title>
<PublishDate>3/31/2014 12:00:00 AM</PublishDate>
<Severity>03</Severity>
<ResponseNecessary>Yes</ResponseNecessary>
<ThreatDate>6/2/2014 12:00:00 AM</ThreatDate>
<DueDate>
</DueDate>
<SystemStandard>Yes</SystemStandard>
<Type>DummyData</Type>
<Overview>DummyDataDummyDataDummyDataDummyDataDummyDataDummyDataDummyDataDummyDataDummyDataDummyData</Overview>
<NIRTAnalysis><p>N/A</p></NIRTAnalysis>
<ThreatAsessment><p>N/A</p></ThreatAsessment>
<ProductsAffected><p>DummyData 10 SP4 LTSS</p></ProductsAffected>
<RequiredActions>DummyDataDummyDataDummyDataDummyDataDummyData</RequiredActions>
<AdditionalInformation>DummyDataDummyDataDummyDataDummyDataDummyData</AdditionalInformation>
<ExternalReference>DummyDataDummyDataDummyDataDummyDataDummyDataDummyData</ExternalReference>
<PatchID>
</PatchID>
</Alert>
And the following xsd file generated by SSIS:
<?xml version="1.0"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Alert">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="AlertID" type="xs:string" />
<xs:element minOccurs="0" name="Title" type="xs:string" />
<xs:element minOccurs="0" name="PublishDate" type="xs:string" />
<xs:element minOccurs="0" name="Severity" type="xs:unsignedByte" />
<xs:element minOccurs="0" name="ResponseNecessary" type="xs:string" />
<xs:element minOccurs="0" name="ThreatDate" type="xs:string" />
<xs:element minOccurs="0" name="DueDate" type="xs:string" />
<xs:element minOccurs="0" name="SystemStandard" type="xs:string" />
<xs:element minOccurs="0" name="Type" type="xs:string" />
<xs:element minOccurs="0" name="Overview" type="xs:string" />
<xs:element minOccurs="0" name="NIRTAnalysis" type="xs:string" />
<xs:element minOccurs="0" name="ThreatAsessment" type="xs:string" />
<xs:element minOccurs="0" name="ProductsAffected" type="xs:string" />
<xs:element minOccurs="0" name="RequiredActions" type="xs:string" />
<xs:element minOccurs="0" name="AdditionalInformation" type="xs:string" />
<xs:element minOccurs="0" name="ExternalReference" type="xs:string" />
<xs:element minOccurs="0" name="PatchID" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
My problem is when I use XML Source to load the file but the source doesn't recognize the columns. I'm guessing it thinks the file has nested nodes because the only way I can get it to see any columns is with the following XSD below, which will see all the columns but all as separate output:
<?xml version="1.0"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Alert">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="AlertID" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="Title" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="PublishDate" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="Severity" type="xs:unsignedByte" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="ResponseNecessary" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="ThreatDate" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="DueDate" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="SystemStandard" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="Type" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="Overview" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="NIRTAnalysis" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="ThreatAsessment" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="ProductsAffected" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="RequiredActions" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="AdditionalInformation" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="ExternalReference" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="PatchID" type="xs:string" />
</xs:sequence>
</xs:complexType>
I don't know a lot about XLST, but I know I can flatten the file that way, but to me, it is flat. Are there any suggestions as to what I'm doing wrong? I believe I just have an xsd problem, but what you see was generated by SSIS.
It seems that the problem is related to the XML itself.
Please add a root element to the xml file and try again with a new SSIS-generated xsd after adding the root.
xml should look like:
<?xml version="1.0"?>
<Root>
<Alert>
....
</Alert>
</Root>
I want to read an XML file and split the data into a parent and 2 child tables. Here is what the SQL schema where the data will go and the XSD. I'm thinking SSIS is what I want to use but not sure how to go about it. Should i iterate through the children and then insert the rows using code. Any ideas would be helpful. I am willing to use something other than SSIS. I using MS SQL Server 2008.
<?xml version="1.0"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="MonthlyReportForm">
<xs:complexType>
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element minOccurs="0" name="ReportingDate" type="xs:string" />
<xs:element minOccurs="0" name="ReportingYear" type="xs:unsignedShort" />
<xs:element minOccurs="0" name="ReportingRegion" type="xs:string" />
<xs:element minOccurs="0" name="TeamMembersName" type="xs:string" />
<xs:element minOccurs="0" name="chkTraining" type="xs:unsignedByte" />
<xs:element minOccurs="0" name="chkVernacularMaterials" type="xs:unsignedByte" />
<xs:element minOccurs="0" name="RDHelpText" type="xs:string" />
<xs:element minOccurs="0" name="chkOutOfCountryForm" type="xs:unsignedByte" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="TravelData">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="TravelRowLocation" type="xs:string" />
<xs:element minOccurs="0" name="TravelRowTeam" type="xs:string" />
<xs:element minOccurs="0" name="TravelRowThisMonth" type="xs:unsignedByte" />
<xs:element minOccurs="0" name="TravelRowNextMonth" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="TrainingReport">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="TrainingData">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="TrainerName" type="xs:string" />
<xs:element minOccurs="0" name="TraineeGender" type="xs:string" />
<xs:element minOccurs="0" name="TraineeAge" type="xs:decimal" />
<xs:element minOccurs="0" name="TraineeLanguage" type="xs:string" />
<xs:element minOccurs="0" name="TraineeEducation" type="xs:string" />
<xs:element minOccurs="0" name="TraineeProvince" type="xs:string" />
<xs:element minOccurs="0" name="TrainingPrepHrs" type="xs:decimal" />
<xs:element minOccurs="0" name="TrainingTrainHrs" type="xs:decimal" />
<xs:element minOccurs="0" name="TrainingArea" type="xs:unsignedByte" />
<xs:element minOccurs="0" name="TrainingActivity" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I'm using Qt C++ and am reading in an XML file for data. I want to ensure the XML file contains valid elements, so I began to write an XML Schema to validate against (Qt doesn't support validating against a DTD). The problem is, I'm not sure if my Schema itself is valid, and I can't seem to find an actual XSD validator. I tried using the official w3c validator at http://www.w3.org/2001/03/webdata/xsv, but it's giving me blank output. Would anyone know of a decent XSD validator, or perhaps be willing to look over the following manually?
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="ballot">
<xs:complexType>
<xs:sequence>
<xs:element name="races">
<xs:complexType>
<xs:element name="race" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="rtitle" minOccurs="1" maxOccurs="1" type="xs:string"/>
<xs:element name="candidates" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:element name="candidate" minOccurs="1" maxOccurs="10">
<xs:complexType>
<xs:element name="candname" minOccurs="1" maxOccurs="1" type="xs:string"/>
<xs:element name="candparty" minOccurs="1" maxOccurs="1" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:complexType>
</xs:element>
<xs:element name="propositions">
<xs:complexType>
<xs:element name="proposition" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:element name="ptitle" minOccurs="1" maxOccurs="1" type="xs:string"/>
<xs:element name="pdesc" minOccurs="1" maxOccurs="1" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Please let me know what you think, I appreciate it!
xs:element can't go directly inside of xs:complexType. Try this:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="ballot">
<xs:complexType>
<xs:sequence>
<xs:element name="races">
<xs:complexType>
<xs:sequence>
<xs:element name="race" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="rtitle" minOccurs="1" maxOccurs="1" type="xs:string"/>
<xs:element name="candidates" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="candidate" minOccurs="1" maxOccurs="10">
<xs:complexType>
<xs:sequence>
<xs:element name="candname" minOccurs="1" maxOccurs="1" type="xs:string"/>
<xs:element name="candparty" minOccurs="1" maxOccurs="1" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="propositions">
<xs:complexType>
<xs:sequence>
<xs:element name="proposition" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="ptitle" minOccurs="1" maxOccurs="1" type="xs:string"/>
<xs:element name="pdesc" minOccurs="1" maxOccurs="1" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
It validates the following sample XML:
<?xml version="1.0" encoding="utf-8"?>
<ballot>
<races>
<race>
<rtitle>rtitle1</rtitle>
<candidates>
<candidate>
<candname>candname1</candname>
<candparty>candparty1</candparty>
</candidate>
<candidate>
<candname>candname2</candname>
<candparty>candparty2</candparty>
</candidate>
</candidates>
</race>
<race>
<rtitle>rtitle2</rtitle>
<candidates>
<candidate>
<candname>candname4</candname>
<candparty>candparty4</candparty>
</candidate>
</candidates>
</race>
</races>
<propositions>
<proposition>
<ptitle>ptitle1</ptitle>
<pdesc>pdesc1</pdesc>
</proposition>
<proposition>
<ptitle>ptitle2</ptitle>
<pdesc>pdesc2</pdesc>
</proposition>
<proposition>
<ptitle>ptitle3</ptitle>
<pdesc>pdesc3</pdesc>
</proposition>
</propositions>
</ballot>
i have a problem that I want to resolve in a best possible way. The thing is that I made a schema that looks like this:
print("
<xs:complexType name="rentACarT">
<xs:sequence>
<xs:element name="poslovnice" type="poslovniceT" />
<xs:element name="korisnici" type="korisniciT" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="poslovniceT">
<xs:sequence>
<xs:element name="poslovnica" type="poslovnicaT" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="poslovnicaT">
<xs:sequence>
<xs:element name="naziv" type="xs:string" />
<xs:element name="adresa" type="adresaT" />
<xs:element name="grad" type="gradT" />
<xs:element name="vozila" type="vozilaT" />
<xs:element name="zaposlenici" type="zaposleniciT" />
<xs:element name="posudbe" type="posudbeT" />
</xs:sequence>
<xs:attribute name="id" type="xs:int" />
</xs:complexType>
<xs:complexType name="vozilaT">
<xs:sequence>
<xs:element name="vozilo" type="voziloT" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="zaposleniciT">
<xs:sequence>
<xs:element name="zaposlenik" type="zaposlenikT" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="korisniciT">
<xs:sequence>
<xs:element name="korisnik" type="korisnikT" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="posudbeT">
<xs:sequence>
<xs:element name="posudba" type="posudbaT" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="posudbaT">
<xs:sequence>
<xs:element name="idVozila" type="xs:int" />
<xs:element name="jmbgZaposlenika" type="jmbgT" />
<xs:element name="jmbgKorisnika" type="jmbgT" />
<xs:element name="datumPosudbe" type="xs:date" />
<xs:element name="ugovoreniDatumPovratka" type="xs:date" />
<xs:element name="stvarniDatumPovratka" type="xs:date" />
</xs:sequence>
<xs:attribute name="id" type="xs:integer" />
</xs:complexType>
<xs:complexType name="voziloT">
<xs:sequence>
<xs:element name="registracija" type="xs:string" />
<xs:element name="modelVozila" type="modelVozilaT" />
<xs:element name="godinaProizvodnje" type="godinaT" />
<xs:element name="cijenaPosudbePoDanu" type="xs:double" />
</xs:sequence>
<xs:attribute name="id" type="xs:int" />
</xs:complexType>
<xs:complexType name="zaposlenikT">
<xs:sequence>
<xs:element name="ime" type="xs:string" />
<xs:element name="prezime" type="xs:string" />
<xs:element name="spol" type="spolT" />
<xs:element name="datumZaposlenja" type="xs:date" />
<xs:element name="grad" type="xs:double" />
</xs:sequence>
<xs:attribute name="jmbg" type="jmbgT" />
</xs:complexType>
<xs:complexType name="korisnikT">
<xs:sequence>
<xs:element name="ime" type="xs:string" />
<xs:element name="prezime" type="xs:string" />
<xs:element name="spol" type="spolT" />
<xs:element name="adresa" type="adresaT" />
<xs:element name="grad" type="gradT" />
<xs:element name="status" type="statusKorisnikaT" />
</xs:sequence>
<xs:attribute name="jmbg" type="jmbgT" />
</xs:complexType>
<xs:complexType name="modelVozilaT">
<xs:sequence>
<xs:element name="tipVozila" type="tipVozilaT" />
<xs:element name="marka" type="xs:string" />
<xs:element name="model" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:simpleType name="tipVozilaT">
<xs:restriction base="xs:string">
<xs:enumeration value="auto" />
<xs:enumeration value="kombi" />
<xs:enumeration value="kamion" />
<xs:enumeration value="limuzina" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="godinaT">
<xs:restriction base="xs:int">
<xs:minInclusive value="1980" />
<xs:maxInclusive value="2050" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="jmbgT">
<xs:restriction base="xs:string">
<xs:pattern value="([0-9]){13}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="spolT">
<xs:restriction base="xs:string">
<xs:enumeration value="m" />
<xs:enumeration value="f" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="statusKorisnikaT">
<xs:restriction base="xs:string">
<xs:enumeration value="stalni" />
<xs:enumeration value="novi" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="gradT">
<xs:sequence>
<xs:element name="postanskiBroj" type="xs:int" />
<xs:element name="naziv" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="adresaT">
<xs:sequence>
<xs:element name="ulica" type="xs:string" />
<xs:element name="kucniBroj" type="xs:int" />
</xs:sequence>
</xs:complexType>
");
Now, I don't want to put the entire xml document into one row. At least I think it is bad.
I would like to move "poslovnice"(contains multiple "poslovnica") in one table and "vozila" in other...
And is it better to hold each "poslovnica" in one row in table Poslovnica or have all elements "poslovnica" in one row?
And what about uniqueness since SQL Server doesn't support unique xml data type, I've seen that you can use triggers and functions, is there any other way?
Also, if I break the xml document, and have poslovnice in one table and their vozila in other, how to achieve to show that vozilo belongs to poslovnica, should I put id of poslovnica in each vozilo in xml or should I reference rows in SQL Server?
Or would you reccomend some other database?
Thank you very much, I am sorry if I wasn't clear enough :( !
Miroslav
well first you have to ask yourself why do you want it stored in XML in the db?
this seems like a perfect scenario to have tables Poslovnica, Vozilo and Zaposlenik and have intermediate tables that hold info on which employee rented what car where.
i don't see a reason to store this in xml at all.