Snippet to create Snippet in SSMS - sql-server

Problem:
Usually, if you want to save your code as a snippet, you have to open some xml template, investigate tags etc. Reference
Is it possible to simplify this process as much as possible: i.e. create a SurroundsWith snippet that will wrap selected code by snippet code?

Please try following:
Save this code as a create_new_snippet.snippet and add it to your SSMS through code snippet manager (Ctrl+K, Ctrk+B)
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Create_new_snippet</Title>
<Shortcut></Shortcut>
<Description>Snippet to create a snippet</Description>
<Author>Denis Sipchenko</Author>
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal> <ID>Title</ID> <Default>NewSnippetTitle</Default> <ToolTip>NewSnippetTitle</ToolTip> </Literal>
<Literal> <ID>Description</ID> <Default>NewSnippetDescription</Default> <ToolTip>NewSnippetDescription</ToolTip> </Literal>
<Literal> <ID>Author</ID> <Default>Unsung Hero</Default> <ToolTip>NewSnippetAuthor</ToolTip> </Literal>
<Literal> <ID>SnippetType</ID> <Default>SurroundsWith</Default> <ToolTip>SurroundsWith OR Expansion</ToolTip> </Literal>
<Literal> <ID>CodeComment</ID> <Default>-- Sorry. I was too lazy to write some usefull comment here</Default> <ToolTip>Comment for you code</ToolTip> </Literal>
</Declarations>
<Code Language="sql"
Delimiter="`">
<![CDATA[<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>`Title`</Title> <!--`Title`.snippet -copy/paste for filename-->
<Shortcut></Shortcut>
<Description>`Description`</Description>
<Author>`Author`</Author>
<SnippetTypes>
<SnippetType>`SnippetType`</SnippetType> <!--SurroundsWith/Expansion-->
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal> <ID></ID> <Default></Default> <ToolTip></ToolTip> </Literal>
</Declarations>
<Code Language="SQL">
<![CDATA[`CodeComment`
$selected$`selected`$end$`end`
]]`fake`>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Select your code (that you want to save as a snippet) and call Surround With... snippet (Edit\IntelliSense\Surround With... Ctrl+K, Ctrl+S)
Edit parameters if necessary (as Title, Description etc...) and save as [YourSnippetName].snippet into your snippet folder.

Related

How to supply unit_count_type and unit_count Amazon product data feed?

I supplied value of unit of Measure and Unit count in _POST_PRODUCT_DATA_ feed.
XmlElement unitOfMeasure = xmlDocument.CreateElement("unitOfMeasure");
unitOfMeasure.InnerText = "Count";
Product.AppendChild(unitOfMeasure);
XmlElement UnitCount = xmlDocument.CreateElement("UnitCount");
UnitCount.InnerText = "1";
Product.AppendChild(UnitCount);
My xml feed looks like this
<?xml version="1.0" encoding="iso-8859-1"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>xxxxxxx</MerchantIdentifier>
</Header>
<MessageType>Product</MessageType>
<PurgeAndReplace>false</PurgeAndReplace>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<Product>
<SKU>book1568388578</SKU>
<StandardProductID>
<Type>ASIN</Type>
<Value>1568388578</Value>
</StandardProductID>
<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
<unitOfMeasure>count</unitOfMeasure>
<UnitCount>1</UnitCount>
<DescriptionData>
<Title>Relapse Prevention Long-term Workbook</Title>
<Brand> </Brand>
<Description> </Description>
<BulletPoint> </BulletPoint>
<BulletPoint> </BulletPoint>
<MSRP currency="USD">70.74</MSRP>
<Manufacturer>Hazelden Foundation,U.S.</Manufacturer>
<ItemType>books</ItemType>
</DescriptionData>
<ProductData>
<Health>
<ProductType>
<HealthMisc>
<Ingredients>Example Ingredients</Ingredients>
<Directions>Example Directions</Directions>
</HealthMisc>
</ProductType>
</Health>
</ProductData>
</Product>
</Message>
</AmazonEnvelope>
I am getting following error in feed result.
XML Parsing Error at Line 19, Column 22: cvc-complex-type.2.4.a: Invalid content was found starting with element &apos;unitOfMeasure&apos;. One of &apos;{LaunchDate, DiscontinueDate, ReleaseDate, ExternalProductUrl, Condition, Rebate, ItemPackageQuantity, NumberOfItems, LiquidVolume, DescriptionData, DiscoveryData, ProductData, ShippedByFreight, EnhancedImageURL, Amazon-Vendor-Only, Amazon-Only, RegisteredParameter, NationalStockNumber, UnspscCode, UVPListPrice}&apos; is expected.
I got the solution. You need to provide this feed of unit count in HealthMisc
Correct xml..
<?xml version="1.0" encoding="iso-8859-1"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>xxxxxxxxxx</MerchantIdentifier>
</Header>
<MessageType>Product</MessageType>
<PurgeAndReplace>false</PurgeAndReplace>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<Product>
<SKU>book1568388578</SKU>
<StandardProductID>
<Type>ASIN</Type>
<Value>1568388578</Value>
</StandardProductID>
<ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
<DescriptionData>
<Title>Relapse Prevention Long-term Workbook</Title>
<Brand> </Brand>
<Description> </Description>
<BulletPoint> </BulletPoint>
<BulletPoint> </BulletPoint>
<MSRP currency="USD">70.74</MSRP>
<Manufacturer>Hazelden Foundation,U.S.</Manufacturer>
<ItemType>books</ItemType>
</DescriptionData>
<ProductData>
<Health>
<ProductType>
<HealthMisc>
<UnitCount unitOfMeasure="Count">1</UnitCount>
<Ingredients>Example Ingredients</Ingredients>
<Directions>Example Directions</Directions>
</HealthMisc>
</ProductType>
</Health>
</ProductData>
</Product>
</Message>
</AmazonEnvelope>

VoiceXML gives 'internal error' but no obvious error is shown

I have created this VoiceXML code to ask the user to fill in some data, which is then supposed to be stored in the database.
When I run the code through Postman to simulate the request, I don't get any errors back. But when I actually run and call my Python/Django voice application I get an 'internal error' back once my application reaches that part.
The VoiceXML output:
<?xml version="1.0" encoding="UTF-8"?>
<!--- <vxml version = "2.1" > -->
<!DOCTYPE vxml SYSTEM "http://www.w3.org/TR/voicexml21/vxml.dtd">
<vxml xmlns="http://www.w3.org/2001/vxml"
version="2.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/vxml
http://www.w3.org/TR/2007/REC-voicexml21-20070619/vxml.xsd">
<!---<property name="inputmodes" value="dtmf" /> -->
<!-- Kasadaka VoiceXML File -->
<form id="input_form">
<property name="inputmodes" value="dtmf" />
<property name="interdigittimeout" value="2s"/>
<property name="timeout" value="4s"/>
<property name="termchar" value="#" />
<field name="DTMF_input" type="digits?maxlength=5">
<prompt>
<audio src="/uploads/petrichor_here_you_can_fill_in_your_farmer_id_en_QL7Xu6T.wav"/>
</prompt>
</field>
<block>
<prompt>
<audio src="/uploads/petrichor_thank_you_for_your_input_en_rFaZyF5.wav"/>
</prompt>
<filled namelist="DTMF_input">
<submit src=" /vxml/InputData/34/18" namelist="DTMF_input" method="post"/>
</filled>
</block>
</form>
</vxml>
And if needed, the code that is supposed to save the input:
def InputData(request, element_id, session_id):
input_element = get_object_or_404(InputData_model, pk=element_id)
voice_service = input_element.service
session = lookup_or_create_session(voice_service, session_id)
if request.method == "POST":
session = get_object_or_404(CallSession, pk=session_id)
value = 'DTMF_input'
result = UserInput()
result.session = session
result.category = input_element.input_category
result.save()
return redirect(request.POST['redirect'])
session.record_step(input_element)
context = input_generate_context(input_element, session)
context['url'] = request.get_full_path(False)
return render(request, 'input.xml', context, content_type='text/xml')
Is my VoiceXML code correct if I want the user to be able to fill in numbers through DTMF and then store that data into my model? Or am I missing something important for it to work?
EDIT: Error Logs:
============================================================
Error Summary
============================================================
An error occurred while executing the following dialog.
Initial URL1: http://petrichor-rain-system.herokuapp.com/vxml/start/3
Initial URL2: null
Initial URL3: null
Current URL: /vxml/choice/35/26
Calling Number (ANI): 447520631888
Called Number (DNIS): 9991494860
Redirecting Number (RDNIS): ""
State: hello-and-welcome
VoiceXML Browser Version: 16.0.25.88606
Date/Time: 2019/4/18 10:4:29.387
VoiceException:
error.badfetch
Could not compile document: http://petrichor-rain-system.herokuapp.com/vxml/InputData/33/26
Dialog stack trace:
State (Dialog) URL (Document)
-------------- ------------------------------
hello-and-welcome http://petrichor-rain-system.herokuapp.com/vxml/choice/35/26
============================================================
Current Document
============================================================
<?xml version="1.0" encoding="UTF-8"?>
<!--- <vxml version = "2.1" > -->
<!DOCTYPE vxml SYSTEM "http://www.w3.org/TR/voicexml21/vxml.dtd">
<vxml xmlns="http://www.w3.org/2001/vxml"
version="2.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/vxml
http://www.w3.org/TR/2007/REC-voicexml21-20070619/vxml.xsd">
<meta name="maintainer" content="email" />
<property name="inputmodes" value="dtmf" />
<!-- Kasadaka VoiceXML File -->
<form id="hello-and-welcome">
<field name="choice">
<prompt>
<audio src="/uploads/petrichor_hello_welcome_en_AwoXmq3.wav"/>
<audio src="/uploads/pre_choice_option_en.wav"/>
<audio src="/uploads/petrichor_press_one_to_listen_to_explanation_en_L6iqUHW.wav"/>
<audio src="/uploads/post_choice_option_en.wav"/>
<audio src="/uploads/1_en.wav"/>
<audio src="/uploads/pre_choice_option_en.wav"/>
<audio src="/uploads/petrichor_press_two_to_fill_in_collected_data_en_zXRGSby.wav"/>
<audio src="/uploads/post_choice_option_en.wav"/>
<audio src="/uploads/2_en.wav"/>
<audio src="/uploads/pre_choice_option_en.wav"/>
<audio src="/uploads/petrichor_press_three_to_stop_the_call_en_bOL0PDC.wav"/>
<audio src="/uploads/post_choice_option_en.wav"/>
<audio src="/uploads/3_en.wav"/>
</prompt>
<grammar xml:lang="en-US" root = "MYRULE" mode="dtmf">
<rule id="MYRULE" scope = "public">
<one-of>
<item>1</item>
<item>2</item>
<item>3</item>
</one-of>
</rule>
</grammar>
<filled>
<if cond="choice == '1'">
<goto next="/vxml/message/18/26"/>
<elseif cond="choice == '2'" />
<goto next="/vxml/InputData/33/26"/>
<elseif cond="choice == '3'" />
<goto next="/vxml/choice/22/26"/>
<else/>
</if>
</filled>
</field>
</form>
</vxml>
To post the results back to the server, you need to use the submit element and not the goto element.
<submit src="/vxml/InputData/34/8" namelist="DTMF_input" method="post"/>
See details in the VoiceXML specification.

Replace XML Span Element with Inner text of Span Tag in SQL Server

Replace span Element with its inner text whose class is "TAGGED_ITEM " in multiple rows with a column of type XML
<Item title="1234" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2">
<ItemBody>
<div class="item_text">
<div>
<span class="TAGGED_ITEM " id="c1_ae1">This is a map on a grid.</span>
<span class="TAGGED_ITEM " id="c1_ae2"> It shows a car.</span>
</div>
<span class="TAGGED_ITEM " id="c1_ae3"> It shows a car on Road.</span>
</div>
</ItemBody>
</Item>
Once Element is updated it should looks as below.
<Item title="1234" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2">
<ItemBody>
<div class="item_text">
<div>
This is a map on a grid.
It shows a car.
</div>
It shows a car on Road.
</div>
</ItemBody>
</Item>
This question had a particular namespace problem which, probably, had aroused the question. Eliminating namespaces on the match= does solve the problem. So an identity transform and a namespace-neutral matching gives the desired result:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[local-name() = 'span']">
<xsl:value-of select="text()" />
</xsl:template>
</xsl:stylesheet>
Result:
<?xml version="1.0"?>
<Item xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2" title="1234">
<ItemBody>
<div class="item_text">
<div>
This is a map on a grid.
It shows a car.
</div>
</div>
</ItemBody>
</Item>

Transfer XML file with a languages section to a database table using XSLT

below is a part of the xml file I get. I want to transfer this to a single mssql database table. My problem are the different languages of each job-element. The three languages below won't change in time.
I want to create 2 columns for each language in the db-table.
Example: EnglishTitle & EnglishDescription
<jobs>
<job nr="1">
<language name="English">
<title>English title</title>
<description>
<li>English description</li>
<li>English description 2</li>
<li>English description 3</li>
</description>
</language>
<language name="German">
<title>German title</title>
<description>German description</description>
</language>
<language name="Chinese">
<title>Business Mission Chinese</title>
<description>German description</description>
</language>
<general>For all languages</general>
</job>
</jobs>
How can I use XSLT to lookup the language name attribute and create two elements for each language with the content of the name attribute?
UPDATE:
This is what I think the output should look like:
<jobs>
<job nr="1">
<EnglishTitle>English title</EnglishTitle>
<EnglishDescription>
<li>English description</li>
<li>English description 2</li>
<li>English description 3</li>
</EnglishDescription>
<GermanTitle>German title</GermanTitle>
<GermanDescription>German description</GermanDescription>
<ChineseTitle>Business Mission Chinese</ChineseTitle>
<ChineseDescription>Chinese description</ChineseDescription>
<general>For all languages</general>
</job>
</jobs>
Additionally how should I store the <li>-Elements
of a description in the table? Should I replace them with new lines or with a special character?
If there is a better way feel free to tell me.
IMHO, you should have a separate row for each individual description, with columns describing the job number (hopefully unique), the language and the description itself. So something like:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/jobs">
<table>
<xsl:for-each select="job/language/description/text() | job/language/description/li ">
<row>
<col><xsl:value-of select="ancestor::job/#nr"/></col>
<col><xsl:value-of select="ancestor::language/#name"/></col>
<col><xsl:value-of select="."/></col>
</row>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
which in your example would return:
<?xml version="1.0" encoding="utf-8"?>
<table>
<row>
<col>1</col>
<col>English</col>
<col>English description</col>
</row>
<row>
<col>1</col>
<col>English</col>
<col>English description 2</col>
</row>
<row>
<col>1</col>
<col>English</col>
<col>English description 3</col>
</row>
<row>
<col>1</col>
<col>German</col>
<col>German description</col>
</row>
<row>
<col>1</col>
<col>Chinese</col>
<col>German description</col>
</row>
</table>

Horizontal menu showing vertically with cssfriendly adapter

I am using cssfriendly latest version but while applyinf Orientation="Horizntal" my manu shows in Verticle format.
Below is my .ASPX code
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" CssSelectorClass="PrettyMenu"
StaticDisplayLevels="2" Orientation="Horizontal" />
Sitemap code
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="default.aspx" title="Home" description="Home page for site">
<siteMapNode url="about/default.aspx" title="About" description="About Us" />
<siteMapNode url="help/default.aspx" title="Help" description="FAQs and SiteMap">
<siteMapNode url="help/faq.aspx" title="FAQ" description="Frequently Asked Questions" />
<siteMapNode url="help/sitemap.aspx" title="Sitemap" description="Map of Site" />
</siteMapNode>
</siteMapNode>
</siteMap>
Please let me suggest any way to resplve this problem.
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="default.aspx" title="Home" description="Home page for site">
<siteMapNode url="help/default.aspx" title="Help" description="FAQs and SiteMap">
<siteMapNode url="help/faq.aspx" title="FAQ" description="Frequently Asked Questions" />
<siteMapNode url="help/sitemap.aspx" title="Sitemap" description="Map of Site" />
</siteMapNode>
</siteMapNode>
<siteMapNode url="about/default.aspx" title="About" description="About Us" />
</siteMap>
Please try this, This will show two menu items "Home" and "About" horozontally, with their childs vertically.

Resources