- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有嵌套的 WSDL,我想将其扁平化。 wsdl 导入 xsd 文件,这些文件又包含其他文件等。我喜欢把整个东西压平成一个文件,以便将它提供给一个无法执行导入/包含的工具。有没有我可以使用的简单工具(也许是命令行)?我尝试使用 xsltproc/xmllint,但它们对 wsdl include 一无所知。
最佳答案
我想我已经很晚了,但为了以防万一其他人需要它,这是我整理的(诚然非常肮脏的)代码片段(通过使用我在不同地方找到的半工作代码并添加一些修复).这需要 .NET 4.5 才能工作,但会很好地扁平化远程 WSDL URL。它可能不会涵盖所有情况,但它在过去 2 年对我有用。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.Services.Discovery;
using System.Xml;
namespace FlattenXml {
internal class Program {
private static XmlDocument m_MapDoc;
private static string m_DocPath;
private static XmlDocument m_FlattenDocument = new XmlDocument();
private static string m_ServiceUri;
private static Dictionary<string, XmlElement> m_Elements = new Dictionary<string, XmlElement>();
private static void Main(string[] args) {
if (args == null || args.Length == 0) {
Program.usage();
} else {
if (args != null && args.Length == 1 && (args[0] == "-h" || args[0] == "-?")) {
Program.usage();
} else {
if (args != null && args.Length == 2) {
Program.m_DocPath = args[1];
Program.m_ServiceUri = args[0];
DiscoveryClientProtocol client = new DiscoveryClientProtocol();
client.DiscoverAny(Program.m_ServiceUri);
client.ResolveAll();
Program.m_DocPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Program.m_DocPath);
Directory.CreateDirectory(Program.m_DocPath);
string mapFile = Path.Combine(Program.m_DocPath, "map.xml");
client.WriteAll(Program.m_DocPath, mapFile);
flattenDocuments(mapFile);
}
}
}
}
private static void usage() {
Console.WriteLine("Usage: flattenxml [Service Wsdl URL] [Output Folder]");
Console.WriteLine("Example: flattenxml http://localhost/Daenet.TrackingService/TrackingService.svc Out");
}
private static void flattenDocuments(string mapFile) {
string rootDocumentName = Program.getRootDocumentFile(mapFile);
Program.m_FlattenDocument = Program.flattenDocument(Path.Combine(Program.m_DocPath, rootDocumentName));
Program.m_FlattenDocument.Save("FlattenDocument.wsdl");
}
private static string getRootDocumentFile(string mapFile) {
XmlDocument mapDoc = new XmlDocument();
mapDoc.Load(mapFile);
Program.m_MapDoc = mapDoc;
foreach (XmlElement el in mapDoc.DocumentElement.FirstChild.OfType<XmlElement>()) {
if (el.Attributes["url"].Value == Program.m_ServiceUri || el.Attributes["url"].Value == Program.m_ServiceUri + "?wsdl") {
return el.Attributes["filename"].Value;
}
}
throw new ApplicationException("Root document annot be determined.");
}
private static XmlDocument flattenDocument(string rootDocumentName) {
XmlDocument unflattenDoc = new XmlDocument();
unflattenDoc.Load(rootDocumentName);
return Program.importElements(unflattenDoc.DocumentElement);
}
private static XmlDocument importElements(XmlElement schemaEl) {
XmlElement root = schemaEl.OwnerDocument.CreateElement("a");
Program.importElement(root, schemaEl);
XmlDocument flattenDoc = new XmlDocument();
flattenDoc.LoadXml(root.FirstChild.OuterXml);
return flattenDoc;
}
private static void importExternalElement(XmlElement typeParentEl, XmlElement typeEl) {
if (typeEl.LocalName.ToLower() == "import" || typeEl.LocalName.ToLower() == "include") {
string importingDocName = Program.getImportingDocName(typeEl);
if (importingDocName != null && !Program.m_Elements.ContainsKey(importingDocName)) {
Program.addComment(typeParentEl, typeEl);
XmlDocument unflattenDoc = new XmlDocument();
unflattenDoc.Load(Path.Combine(Program.m_DocPath, importingDocName));
Program.m_Elements.Add(importingDocName, null);
XmlElement importedEl = typeParentEl.OwnerDocument.CreateElement("a");
Program.importElement(importedEl, unflattenDoc.DocumentElement);
// B: for WSDL, inner "definitions" and "policy" elements should be skipped. For all other cases (i.e. XSD) everything should be included
if (typeParentEl.LocalName.ToLower() == "definitions" && typeParentEl.LocalName == importedEl.FirstChild.LocalName) {
Program.mergeNamespaces(typeParentEl, importedEl.FirstChild as XmlElement);
foreach (XmlElement cEl in importedEl.FirstChild.ChildNodes.OfType<XmlElement>()) {
// B: skip policy definitions from internal WSDLs
if (cEl.LocalName.ToLower() == "policy") {
continue;
}
XmlElement cEl2 = cEl.OwnerDocument.CreateElement("a");
cEl2.InnerXml = cEl.OuterXml;
typeParentEl.InsertBefore(cEl2.FirstChild, typeEl);
}
} else {
typeParentEl.InsertBefore(importedEl.FirstChild, typeEl);
}
Program.m_Elements[importingDocName] = importedEl;
}
typeParentEl.RemoveChild(typeEl);
return;
}
throw new ArgumentException();
}
private static XmlElement importElement(XmlElement typeParentEl, XmlElement typeEl) {
XmlElement resultingElement;
if (typeEl.ChildNodes.Count > 0) {
XmlElement newEl = typeParentEl.OwnerDocument.CreateElement("a");
newEl.InnerXml = typeEl.OuterXml;
if (typeEl.ChildNodes.OfType<XmlElement>().Count<XmlElement>() > 0) {
newEl.FirstChild.InnerXml = "";
foreach (XmlElement child in typeEl.ChildNodes.OfType<XmlElement>()) {
if (child.LocalName.ToLower() == "import" || child.LocalName.ToLower() == "include") {
XmlElement impEl = newEl.OwnerDocument.CreateElement("a");
impEl.InnerXml = child.OuterXml;
XmlElement x = newEl.FirstChild.AppendChild(impEl.FirstChild) as XmlElement;
Program.importExternalElement(newEl.FirstChild as XmlElement, x);
} else {
Program.importElement(newEl.FirstChild as XmlElement, child);
}
}
}
resultingElement = Program.appendElement(typeParentEl, newEl.FirstChild);
} else {
if (typeParentEl.ChildNodes.OfType<XmlElement>().Count((XmlElement e) => e.LocalName == typeEl.LocalName) >= 1) {
}
resultingElement = Program.appendElement(typeParentEl, typeEl);
}
return resultingElement;
}
private static XmlElement appendElement(XmlElement parentEl, XmlNode childNode) {
XmlElement newEl = parentEl.OwnerDocument.CreateElement("a");
newEl.InnerXml = childNode.OuterXml;
return parentEl.AppendChild(newEl.FirstChild) as XmlElement;
}
private static XmlDocument loadUnflattenDocument(string importingDoc) {
XmlDocument unflattenDoc = new XmlDocument();
unflattenDoc.Load(Path.Combine(Program.m_DocPath, importingDoc));
XmlDocument flattenDoc = new XmlDocument();
return unflattenDoc;
}
private static XmlDocument loadDocumentFromImportNode(XmlElement importEl) {
string importingDoc = Program.getImportingDocName(importEl);
XmlDocument unflattenDoc = new XmlDocument();
unflattenDoc.Load(Path.Combine(Program.m_DocPath, importingDoc));
return unflattenDoc;
}
private static string getImportingDocName(XmlElement importEl) {
return Program.getImportingDocName(Program.getImportingDocReference(importEl));
}
private static string getImportingDocReference(XmlElement importEl) {
if (importEl.LocalName.ToLower() == "import" || importEl.LocalName.ToLower() == "include") {
if (importEl.Attributes["location"] != null) {
return importEl.Attributes["location"].Value;
} else if (importEl.Attributes["schemaLocation"] != null) {
return importEl.Attributes["schemaLocation"].Value;
}
}
Console.WriteLine("Invalid node, ignored:");
Console.WriteLine(importEl.OuterXml);
return null;
}
private static string getImportingDocName(string docReference) {
if (docReference == null) return null;
// NOTE: [B] the following fix required .NET 4.5, because before .NET 4.5. the URLs were not URLEncoded, which was wrong. The extra check below allows it run with .NET 3.5 or later
var docReferenceRaw = Uri.UnescapeDataString(docReference);
XmlElement refEl = Program.m_MapDoc.DocumentElement.FirstChild.ChildNodes.OfType<XmlElement>().FirstOrDefault((XmlElement el) => el.Attributes["url"].Value == docReference || el.Attributes["url"].Value == docReferenceRaw);
if (refEl != null) {
return refEl.Attributes["filename"].Value;
}
throw new ApplicationException("Mapping error");
}
private static void addComment(XmlElement parentEl, XmlElement importEl) {
var location = Program.getImportingDocReference(importEl);
var path = location == null ? "" : new Uri(Program.getImportingDocReference(importEl)).PathAndQuery;
XmlComment commentEl = parentEl.OwnerDocument.CreateComment("Begin \"" + path + "\"");
parentEl.InsertBefore(commentEl, importEl);
XmlComment commentEl2 = parentEl.OwnerDocument.CreateComment("End \"" + path + "\"");
parentEl.InsertAfter(commentEl2, importEl);
}
private static void mergeNamespaces(XmlElement el1, XmlElement el2) {
foreach (XmlAttribute attr in new List<XmlAttribute>(el2.Attributes.OfType<XmlAttribute>())) {
if (el1.Attributes.OfType<XmlAttribute>().Count((XmlAttribute e) => e.Name == attr.Name) == 0) {
el1.Attributes.Append(attr);
}
}
}
}
}
希望这对您有所帮助。
关于wsdl - 是否有一个简单的工具来展平 wsdl 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17422973/
我有一个 if 语句,如下所示 if (not(fullpath.lower().endswith(".pdf")) or not (fullpath.lower().endswith(tup
然而,在 PHP 中,可以: only appears if $foo is true. only appears if $foo is false. 在 Javascript 中,能否在一个脚
XML有很多好处。它既是机器可读的,也是人类可读的,它具有标准化的格式,并且用途广泛。 它也有一些缺点。它是冗长的,不是传输大量数据的非常有效的方法。 XML最有用的方面之一是模式语言。使用模式,您可
由于长期使用 SQL2000,我并没有真正深入了解公用表表达式。 我给出的答案here (#4025380)和 here (#4018793)违背了潮流,因为他们没有使用 CTE。 我很欣赏它们对于递
我有一个应用程序: void deleteObj(id){ MyObj obj = getObjById(id); if (obj == null) { throw n
我的代码如下。可能我以类似的方式多次使用它,即简单地说,我正在以这种方式管理 session 和事务: List users= null; try{ sess
在开发J2EE Web应用程序时,我通常会按以下方式组织我的包结构 com.jameselsey.. 控制器-控制器/操作转到此处 服务-事务服务类,由控制器调用 域-应用程序使用的我的域类/对象 D
这更多是出于好奇而不是任何重要问题,但我只是想知道 memmove 中的以下片段文档: Copying takes place as if an intermediate buffer were us
路径压缩涉及将根指定为路径上每个节点的新父节点——这可能会降低根的等级,并可能降低路径上所有节点的等级。有办法解决这个问题吗?有必要处理这个吗?或者,也许可以将等级视为树高的上限而不是确切的高度? 谢
我有两个类,A 和 B。A 是 B 的父类,我有一个函数接收指向 A 类型类的指针,检查它是否也是 B 类型,如果是将调用另一个函数,该函数接受一个指向类型 B 的类的指针。当函数调用另一个函数时,我
有没有办法让 valgrind 使用多个处理器? 我正在使用 valgrind 的 callgrind 进行一些瓶颈分析,并注意到我的应用程序中的资源使用行为与在 valgrind/callgrind
假设我们要使用 ReaderT [(a,b)]超过 Maybe monad,然后我们想在列表中进行查找。 现在,一个简单且不常见的方法是: 第一种可能性 find a = ReaderT (looku
我的代码似乎有问题。我需要说的是: if ( $('html').attr('lang').val() == 'fr-FR' ) { // do this } else { // do
根据this文章(2018 年 4 月)AKS 在可用性集中运行时能够跨故障域智能放置 Pod,但尚不考虑更新域。很快就会使用更新域将 Pod 放入 AKS 中吗? 最佳答案 当您设置集群时,它已经自
course | section | type comart2 : bsit201 : lec comart2 :
我正在开发自己的 SDK,而这又依赖于某些第 3 方 SDK。例如 - OkHttp。 我应该将 OkHttp 添加到我的 build.gradle 中,还是让我的 SDK 用户包含它?在这种情况下,
随着 Rust 越来越充实,我对它的兴趣开始激起。我喜欢它支持代数数据类型,尤其是那些匹配的事实,但是对其他功能习语有什么想法吗? 例如标准库中是否有标准过滤器/映射/归约函数的集合,更重要的是,您能
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 9 年前。 Improve
我一直在研究 PHP 中的对象。我见过的所有示例甚至在它们自己的对象上都使用了对象构造函数。 PHP 会强制您这样做吗?如果是,为什么? 例如: firstname = $firstname;
...比关联数组? 关联数组会占用更多内存吗? $arr = array(1, 1, 1); $arr[10] = 1; $arr[] = 1; // <- index is 11; does the
我是一名优秀的程序员,十分优秀!