GVKun编程网logo

mssql for xml path使用

1

如果您想了解mssqlforxmlpath使用的相关知识,那么本文是一篇不可错过的文章,我们将为您提供关于AJAX=AsynchronousJavaScriptandXML(异步的JavaScript

如果您想了解mssql for xml path使用的相关知识,那么本文是一篇不可错过的文章,我们将为您提供关于AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)开学学习在了、Android:Theme.xml 和 Styles.xml?、c# – 响应消息的内容类型application / xml; charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8)、Groovy(conncet DB, generate xml, get response xml, compare two xml)的有价值的信息。

本文目录一览:

mssql for xml path使用

mssql for xml path使用

准备工作:

CREATE TABLE [dbo].[Students](

    [id] [int] IDENTITY(1,1) NOT NULL,

    [names] [varchar](50) NULL,

    [hobby] [varchar](50) NULL

)

 

insert into students values('张三','书法'),('张三','篮球'),('张三','台球'),('李四','书法'),('李四','唱歌'),('李四','足球'),('李四','乒乓球')

 

 

 

for xml path

把查询结果用xml表现出来。

1 正常的查询:

select * from Students

结果是:

 

id names hobby
----------- --------------------------------------------------
1 张三 书法
2 张三 篮球
3 张三 台球
4 李四 书法
5 李四 唱歌
6 李四 足球
7 李四 乒乓球

 

返回的是一个数据表格(多条)。

2 用xml表现

select * from Students for xml path

结果是:

 

XML_F52E2B61-18A1-11d1-B105-00805F49916B
------------------------------------------------------------------------------------
<row><id>1</id><names>张三</names><hobby>书法</hobby></row><row><id>2</id><names>张三</names><hobby>篮球</hobby></row

><row><id>3</id><names>张三</names><hobby>台球</hobby></row><row><id>4</id><names>李四</names><hobby>书法</hobby></row>

<row><id>5</id><names>李四</names><hob

也是一个数据表格(单条) 

把查询结果做为xml数据格式返回了一行数据。

3 通过使用path()参数,可改变列节点:

select * from Students for xml path('')

结果:

 

XML_F52E2B61-18A1-11d1-B105-00805F49916B
-----------------------------------------------------------------------------------
<id>1</id><names>张三</names><hobby>书法</hobby><id>2</id><names>张三</names><hobby>篮球</hobby>

<id>3</id><names>张三</names><hobby>台球</hobby><id>4</id><names>李四</names><hobby>书法</hobby>

<id>5</id><names>李四</names><hobby>唱歌</hobby><id>6</id><names>李四</names><hobby>足球

使用path(‘’)空参数,去掉了row节点,直接显示的是两个属性字段。

4 自定义节点

select * from Students for xml path('selfNode')

结果如下:

XML_F52E2B61-18A1-11d1-B105-00805F49916B
--------------------------------------------------------------------------------------------
<selfNode><id>1</id><names>张三</names><hobby>书法</hobby></selfNode>

<selfNode><id>2</id><names>张三</names><hobby>篮球</hobby></selfNode>

<selfNode><id>3</id><names>张三</names><hobby>台球</hobby></selfNode>

<selfNode><id>4</id><names>李四</names><hobby>书法</hobby></selfNode>

 

总的来说,for xml path返回的是一条数据(一个xml字串)。所以,这个可以作为查询中的一列。如下:

select distinct aaa.names,hobby=(

SELECT hobby+',' FROM students

  WHERE names=aaa.names

  FOR XML PATH('') 

  ) 

  from students aaa

结果如下:

 

names hobby
-------------------------------------------------- 
李四 书法,唱歌,足球,乒乓球,
张三 书法,篮球,台球,

从students表中查询names,且各自的hobby,hobby是多条记录,通过xml 整合到一条记录,并使用逗点分隔。

上面的语句中有一句:where names=aaa.names,因为for xml path返回的是一条数据字串,不能进行查询条件的关联,即不能做为数据表与其它表进行关联。 

它只返回一行一列,且for xml path都整合到一字符串中而没有其它字段,所以不能与其它表进行联合查询。但可以在for xml之前进行联合查询,如下:

select distinct aaa.names,hobby=(

select hobby+',' FROM students

  where names=aaa.names

  for xml path('')

  )   from students aaa 

for xml path部分的结果做为一个字段显示,而粗体部分表示把每个names中的hobby字段通过逗号连成一个字段,如下:

names hobby
--------------------------------------------------
李四 书法,唱歌,足球,乒乓球,
张三 书法,篮球,台球, 

未使用distinct,结果如下: 

names hobby
--------------------------------------------------
张三 书法,篮球,台球,
张三 书法,篮球,台球,
张三 书法,篮球,台球,
李四 书法,唱歌,足球,乒乓球,
李四 书法,唱歌,足球,乒乓球,
李四 书法,唱歌,足球,乒乓球,
李四 书法,唱歌,足球,乒乓球,

把重复的去掉,可通过group或distinct去掉

 

 另外:对于可容忍的脏读而不死锁的with onlock在mssql中可在表后边使用with(nolock)脏读;今天查了一下,对于MysqL来说,不需要使用with nolock,会自动使用nolock. 。这个我自己未做过测试,大概只是了解一下。

AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)开学学习在了

AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)开学学习在了

AJAX

AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)。

AJAX 不是新的编程语言,而是一种使用现有标准的新方法。

AJAX 是与服务器交换数据并更新部分网页的艺术,在不重新加载整个页面的情况下。

开始学习 AJAX!

什么是 AJAX ?

AJAX = 异步 JavaScript 和 XML。

AJAX 是一种用于创建快速动态网页的技术。

通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新。这意味着可以在不重新加载整个网页的情况下,对网页的某部分进行更新。

传统的网页(不使用 AJAX)如果需要更新内容,必需重载整个网页面。

有很多使用 AJAX 的应用程序案例:新浪微博、Google 地图、开心网等等。

AJAX 实例解释

上面的 AJAX 应用程序包含一个 div 和一个按钮。

div 部分用于显示来自服务器的信息。当按钮被点击时,它负责调用名为 loadXMLDoc() 的函数:

<html>
<body>

<div id="myDiv"><h3>Let AJAX change this text</h3></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

</body>
</html>

接下来,在页面的 head 部分添加一个 <script> 标签。该标签中包含了这个 loadXMLDoc() 函数:

<head>
<script type="text/javascript">
function loadXMLDoc()
{
.... AJAX script goes here ...
}
</script>
</head>

下面的章节会为您讲解 AJAX 的工作原理。

Android:Theme.xml 和 Styles.xml?

Android:Theme.xml 和 Styles.xml?

如何解决Android:Theme.xml 和 Styles.xml??

在较新版本的 Android Studio 中,我看不到 styles.xml,但在 values 目录中,有两个新的 XMLtheme.xmltheme.xml(night) .

它是否真的取代了styles.xml OR 如果不同,它们之间的区别是什么??

解决方法

styles 是一组属性,用于定义特定 ui 的外观 例如:editText 或 textView 主题同时决定了整个应用的外观(单个主题可以有多种样式取决于您的设计) ),白天和黑夜两种主题的区别在于让您的应用程序适应白天模式和夜间模式。因为现在在 android 操作系统中你可以强制暗模式。

作为开发者,您需要为此准备好您的应用。

如何使用

为您在项目中标记的两个主题赋予不同的颜色(以下来自主题文件)

  <resources xmlns:tools="http://schemas.android.com/tools">
   <!-- Base application theme. -->
   <style name="Theme.<Your app name>" <---- this is autogenrated this wil be the id to be used
   parent="Theme.MaterialComponents.DayNight">
     </style>
     </resources>

要在 textview 或按钮或布局文件中简单地使用:

    <TextView
    android:id="@+id/tv_StackOverflow"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/> <---insert your style name inside the theme.

现在,当用户在手机的开发者模式下强制开启暗模式时,您的应用将立即适应它并更改其 UI 的颜色。

可以在此处找到更多信息 - https://developer.android.com/guide/topics/ui/look-and-feel/themes

,

res\values 中使用 XML 属性实际上并不依赖于文件名,您可以在另一个文件(如 style.xml)中定义任何一个,例如 <string>

您甚至可以将 style.xml 的名称更改为您喜欢的名称。

在最近的 Android Studio 版本中,styles.xmlthemes.xml 取代,但后者为黑暗模式提供了夜间版本。

c# – 响应消息的内容类型application / xml; charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8)

c# – 响应消息的内容类型application / xml; charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8)

我试图使用独立应用程序使用WCF Web服务.我可以使用Internet Explorer查看此服务,也可以在Visual studio服务引用中查看.

这是我得到的错误

The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8).

如何更改此使用正确的内容类型?

这是我的配置文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="G2WebServiceSoap11Binding" />
        </basicHttpBinding>
        <customBinding>
            <binding name="G2WebServiceSoap12Binding">
                <textMessageEncoding messageVersion="Soap12" />
                <httpTransport />
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="http://XXX.XX.XX.XX:XX/janus/services/G2WebService.G2WebServiceHttpSoap11Endpoint/"
            binding="basicHttpBinding" bindingConfiguration="G2WebServiceSoap11Binding"
            contract="G2ServiceReference.G2WebServicePortType"
            name="G2WebServiceHttpSoap11Endpoint" />
        <endpoint address="http://XXX.XX.XX.XX:XX/janus/services/G2WebService.G2WebServiceHttpSoap12Endpoint/"
            binding="customBinding" bindingConfiguration="G2WebServiceSoap12Binding"
            contract="G2ServiceReference.G2WebServicePortType"
            name="G2WebServiceHttpSoap12Endpoint" />
    </client>
</system.serviceModel>

这里是堆栈

{System.ServiceModel.ProtocolException: The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder,be sure that the IsContentTypeSupported method is implemented properly. 
The first 1024 bytes of the response were: '<Exception>org.apache.axis2.AxisFault: The endpoint reference (EPR) for the Operation not found is /janus/services/G2WebService and the WSA Action = null&#xd;
    at org.apache.axis2.engine.dispatchPhase.checkPostConditions(dispatchPhase.java:89)&#xd;
    at org.apache.axis2.engine.Phase.invoke(Phase.java:333)&#xd;
    at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:264)&#xd;
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:163)&#xd;
    at org.apache.axis2.transport.http.util.RESTUtil.invokeAxisEngine(RESTUtil.java:136)&#xd;
    at org.apache.axis2.transport.http.util.RESTUtil.processURLRequest(RESTUtil.java:130)&#xd;
    at org.apache.axis2.transport.http.AxisServlet$RestRequestProcessor.processURLRequest(AxisServlet.java:829)&#xd;
    at org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:255)&#xd;
    at com.rm.janus.webservice.GroupCallServlet.doGet(GroupCallServlet.java:33)&#xd;
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)&#xd;
    at javax.servlet.http.HttpSer'. ---> System.Net.WebException: The Remote Server returned an error: (500) Internal Server Error.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   --- End of inner exception stack trace ---

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request,HttpWebResponse response,HttpChannelFactory`1 factory,WebException responseException,ChannelBinding channelBinding)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message,TimeSpan timeout)
   at System.ServiceModel.dispatcher.RequestChannelBinder.Request(Message message,TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object[] ins,Object[] outs,TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData,Int32 type)
   at InetgrisG2TestApp.G2ServiceReference.G2WebServicePortType.getStudentData(getStudentDataRequest request)
   at InetgrisG2TestApp.G2ServiceReference.G2WebServicePortTypeClient.G2TestApp.G2ServiceReference.G2WebServicePortType.getStudentData(getStudentDataRequest request) in c:\Users\s\Documents\Visual Studio 2012\Projects\G2TestApp\InetgrisG2TestApp\Service References\G2ServiceReference\Reference.cs:line 2981
   at InetgrisG2TestApp.G2ServiceReference.G2WebServicePortTypeClient.getStudentData(ServiceRequest serviceReq) in c:\Users\s\Documents\Visual Studio 2012\Projects\G2TestApp\G2TestApp\Service References\G2ServiceReference\Reference.cs:line 2987
   at InetgrisG2TestApp.Program.Main(String[] args) in c:\Users\s\Documents\Visual Studio 2012\Projects\G2TestApp\G2TestApp\Program.cs:line 57}

解决方法

您的WCF服务可能返回HTML.在这种情况下,您将需要在服务端设置绑定以返回XML.但是,这是不可能的:如果是这样的话,让我知道,我会进行更多的细节编辑.

更可能的原因是您的服务发生错误,这是返回HTML错误页面.你可以看看this blog post如果你想要的细节.

TL;博士:
错误页面有几种可能的配置.如果您在IIS上托管,则需要删除< httpErrors>部分来自WCF服务的web.config文件.如果没有,请提供您的服务托管场景的详细信息,我可以提出一个编辑来匹配它们.

编辑:

看到您的编辑后,您可以看到正在返回的完整错误. Apache无法确定您要调用哪个服务,并且因此导致错误.一旦您拥有正确的端点,该服务就会正常工作 – 您指向错误的位置.不幸的是,从信息中可以看出正确的位置是什么,但您的操作(当前为空!)或URL不正确.

Groovy(conncet DB, generate xml, get response xml, compare two xml)

Groovy(conncet DB, generate xml, get response xml, compare two xml)

import groovy.sql.sql
import groovy.xml.MarkupBuilder
import org.custommonkey.xmlunit.*

//Conect to DB and get the nessecery data to generate the expected Xml.
sql sql=context.dbConnection;
def writer = new StringWriter();
def xml = new groovy.xml.MarkupBuilder(writer)
xml.RetailerGroups(){
   RetailerGroup(Name:"Checkout",Id:"CO")
  
   {
   Retailers(){
    Retailer(Name:"Acme",Id:"Acm")
    Retailer(Name:"Acme2",Id:"Acm2")
    def res = sql.firstRow("select scdprj.user3 as ''Brand'',"
    + "schedwin.unix_date_conv (scdslg.air_start) as ''StartDate'',"
    + "schedwin.unix_date_conv (scdslg.air_end) as ''EndDate'',"
    + "scdprj.cl_id as AdvertiserId,clnt.name + '' '' + ''-''+ '' '' + user3 as CampaignName,clnt.name as AdvertiserName "
    + "From schedwin.PROJECTS scdprj "
    + "Inner join schedwin.SLGUSAGE scdslg "
    + "ON scdprj.prj_id=scdslg.prj_id "
    + "Join schedwin.CLNT clnt "
    + "ON clnt.cl_id=scdprj.cl_id "
    + "Where  scdprj.cl_id=1228 and (scdprj.stat=1) and scdprj.formid=0 "
    + "AND (DATEDIFF(dd,schedwin.unix_date_conv(scdslg.AIR_END),''20090707'') < =0) "
    + "AND (DATEDIFF(dd,schedwin.unix_date_conv(scdslg.AIR_START),''20090707'') >= 0) ")
     }
     }
   RetailerGroup(Name:"Checkout",Id:"CO")
  }
 
def expectedResult = writer.toString()
log.info writer.toString() 
XMLUnit.setIgnoreWhitespace(true)

//Get the actual result
def step = testRunner.testCase.testSteps["retailer"]
def result = step.testRequest.response.contentAsstring
log.info result

//Check the actual result by expected result,and output the test result.def xmlDiff = new Diff(result,expectedResult)def s = xmlDiff.toString();File f = new File("c:/","d.txt"); if( !f.exists()){ f.createNewFile(); }try {    FileWriter fileWriter = new FileWriter(f,true);       if (s == "org.custommonkey.xmlunit.Diff[identical]"){       fileWriter.write("API: ''"+ step.name + "'' DV Result is  "+ "Passed/r/n");       }       else{        fileWriter.write("API: ''"+ step.name + "'' DV Result is  "+ "Failed/r/n");        }       fileWriter.close();        } catch (IOException e) {            e.printstacktrace();        }    

关于mssql for xml path使用的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)开学学习在了、Android:Theme.xml 和 Styles.xml?、c# – 响应消息的内容类型application / xml; charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8)、Groovy(conncet DB, generate xml, get response xml, compare two xml)的相关信息,请在本站寻找。

本文标签: