首页 \ 问答 \ RegEx - 当版本#不是“1.0”时匹配XML声明[关闭](RegEx - Match on XML declarations when the version # is not “1.0” [closed])

RegEx - 当版本#不是“1.0”时匹配XML声明[关闭](RegEx - Match on XML declarations when the version # is not “1.0” [closed])

我想用RegEx来做这件事。

我需要找到错误的XML声明和任何非1.0版本的声明

以下是有效的匹配:

不好的声明

<? xml ver="1.0" encoding="UTF-8"?>

不好的声明

<?xml version="1.0' encoding=UTF-8>

不好的声明

<?xml ?>

错误声明(不在第一行开始)

 .....   
<? xml ver="1.0" encoding="UTF-8"?>

版本1.1(单引号)

<?xml version='1.1' encoding='UTF-8'?>

版本1.1(双引号)

<?xml version="1.1" encoding="UTF-8"?>

错误的版本#

<?xml version='999999' encoding='UTF-8'?>

版本1.1(多行) - 不确定是否允许多行格式化,但我已经看到它已完成,我需要检查它。

<?xml 
version="1.1" 
encoding="UTF-8" 
standalone="no" ?>


我们只希望对无效的XML声明匹配使用1.0以外版本的 XML声明

以下是有效的XML 1.0声明。 这些应该永远不会返回匹配:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?> 

<?xml version= "1.0" encoding= 'UTF-8' standalone= "no" ?>

<?xml 
version="1.0" 
encoding="UTF-8" 
standalone="no" ?>

I want to use RegEx for this.

I need to find errant XML declarations AND anything that is not version 1.0

The following would be valid matches:

Bad declaration

<? xml ver="1.0" encoding="UTF-8"?>

Bad declaration

<?xml version="1.0' encoding=UTF-8>

Bad declaration

<?xml ?>

Bad declaration (doesn't start on the first line)

 .....   
<? xml ver="1.0" encoding="UTF-8"?>

Version 1.1 (single quotes)

<?xml version='1.1' encoding='UTF-8'?>

Version 1.1 (double quotes)

<?xml version="1.1" encoding="UTF-8"?>

Erroneous version #

<?xml version='999999' encoding='UTF-8'?>

Version 1.1 (multi-line) - Not sure if multi-line formatting is allowed but I've seen it done and I need to check for it.

<?xml 
version="1.1" 
encoding="UTF-8" 
standalone="no" ?>


We only want matches on invalid XML declarations OR XML declarations with a version other than 1.0

The following as valid XML 1.0 declarations. These should never return a match:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?> 

<?xml version= "1.0" encoding= 'UTF-8' standalone= "no" ?>

<?xml 
version="1.0" 
encoding="UTF-8" 
standalone="no" ?>

原文:https://stackoverflow.com/questions/43415215
更新时间:2023-03-01 10:03

最满意答案

听起来你正试图做一些类似于我在回答有关IList与NHibernate和WCF的问题时所描述的内容 由于您在服务和客户端之间共享合同程序集,因此也将共享List反序列化代码。 我成功地使用了这种技术和ChannelFactory方法,希望它适合你。


Sounds like you're trying to do something similar to what I describe in my answer to a question on IList with NHibernate & WCF. Since you are sharing the contract assembly between the service and the client, the List deserialization code will also be shared. I have used this technique with a ChannelFactory approach successfully, hope it works for you.

相关问答

更多
  • 端点绑定限制(basicHTTP)不支持SAML2 afaik,ADFS2.0似乎只提供承载令牌并且在事实也是非启动之后修改令牌(WIF建议的覆盖这样做似乎不起作用)正如预期的那样)最后因为Web服务不在https之后,安全模式为none(这是唯一可以使用的模式)意味着没有令牌被发送..啊,好吧,回到绘图板! End point binding limitations (basicHTTP) doesn't support SAML2 afaik, also ADFS2.0 only seems to su ...
  • 如果你想使用lambda对代码进行分解,我建议编写一个如下所示的方法: ... public void ServiceCall(Action action) { IFileService proxy = null; ChannelFactory factory = null; try { factory = new ChannelFactory("*"); pr ...
  • 您可以使用通用包装方法: public TProxy CreateChannel(string newEndpointAddress) { _endpointAddress = newEndpointAddress; var factory = new ChannelFactory(new NetTcpBinding(), new EndpointAddress(newEndpointAddress)); return factory.Cr ...
  • 是的,如果你想创建这样的东西 - 一个静态类来保存所有的ChannelFactory实例 - 你绝对必须确保这个类是100%的线程安全的,不能同时访问时绊倒。 我还没有使用.NET 4的功能,所以我不能专门评论那些 - 但我一定会建议尽可能安全。 对于你的第二个(次要的)问题:ChannelFactory本身是一个静态类 - 所以你不能真正调用一个.Close()方法。 如果您打算询问是否在实际的IChannel上调用.Close()方法,那么再次:是的,尽可能地成为一个好的公民,如果可以的话关闭这些 ...
  • 要使序列化程序解释您的合同,需要根据具体类型而不是接口来表达。 如果您将代码更改为此(并使用适当的DataContract和DataMember属性注释类B,那么您应该很高兴。 [DataContract] public class A { [DataMember] public List ListOfB { get; set; } } For the serializer to interpret your contract they need to be expressed i ...
  • 每分钟10次并不常见。 每秒10次我绝对会考虑重用频道。 你的案子中有很多未知数要做出正确的决定。 有多少客户将连接到该服务? 这有什么样的联系(它有可能会在几分之一秒内停止),是否有负载均衡器? 代理? 顺便说一句,如果您决定每次都打开和关闭频道,则无需重新创建ChannelFactory。 保持静态,每次只打开和关闭一个新频道。 大多数时候创建工厂会消耗更多资源。 10 times a minute is not that often. 10 times a second i would definit ...
  • 我相信你需要检查通道的状态,而不是工厂。 您可以通过将通道转换为ICommunicationObject来实现此目的, ICommunicationObject在通道和工厂中实现。 像这样的东西: ChannelFactory factory = new ChannelFactory("NetTcpBinding_IContract", ...
  • 查看我的答案手动将ClientBase集合类型从Array []更改为List <> NHibernate投影和DataContract投影是否必须相同? 我不太了解NHibernate,但是你可以做这样的事吗? public class Channel : EntityBase{ //For WCF [DataMember(Name="LocalChannel")] private List LocalChannelsPrivate { get {ret ...
  • 听起来你正试图做一些类似于我在回答有关IList与NHibernate和WCF的问题时所描述的内容。 由于您在服务和客户端之间共享合同程序集,因此也将共享List反序列化代码。 我成功地使用了这种技术和ChannelFactory方法,希望它适合你。 Sounds like you're trying to do something similar to what I describe in my answer to a question on IList with NHibernate & WCF. Si ...
  • 如果您有任何非.NET的客户端(例如Java或PHP), ChannelFactory将不适用于它们,因为它特定于.NET和WCF。 在这种情况下,您要么必须发布元数据或向客户端发送WSDL,以便他们可以通过他们选择的语言使用的任何方式创建代理(我不太了解Java,PHP等,所以我可以'说明不止于此。) 至于使用ChannelFactory ,我假设您正在谈论ChannelFactory ,因为ChannelFactory本身是一个抽象类,无法实例化。 使用通道工厂提供了更大程度的控制(正如其他人指出 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)