简体   繁体   English

在Bash中使用xmllint从WSDL文件检索信息

[英]Retrieve information from WSDL file using xmllint in Bash

Can I use xmllint to retrieve information from a ".wsdl" file similar to how I would from an ".xml" file in Bash? 我可以使用xmllint从“ .wsdl”文件中检索信息,类似于在Bash中从“ .xml”文件中检索信息吗?

To put things into context, I have an xml file, which I use xmllint to get certain information in the following way in my Bash script: 为了将内容放到上下文中,我有一个xml文件,我使用xmllint通过以下方式在Bash脚本中获取某些信息:

init_variable=$(xmllint --xpath 'string(/tag1/tag2/tag3/attribute)' SampleMessages.xml)

where the "tags" represent the hierarchy in my xml and the attribute is the content of the attribute I retrieve the information from. 其中的“标签”代表我的xml中的层次结构,而属性是我从中检索信息的属性的内容。 This code works when the file is ".xml" 当文件为“ .xml”时,此代码有效

When I try to do the same with a ".wsdl" file, I get an error. 当我尝试对“ .wsdl”文件执行相同操作时,出现错误。 Essentially, I'm trying to do the same thing as above with xmllint . 本质上,我正在尝试使用xmllint与上述相同的xmllint However, each tag in that file is preceded with an wsdl: (see example below). 但是,该文件中的每个标记都以wsdl:开头(请参见下面的示例)。

I'm trying to run the following: 我正在尝试运行以下命令:

serviceDescription=$(xmllint --xpath 'string(/wsdl:tag1/wsdl:tag2/wsdl:attribute)' ExampleFile.wsdl)

When I run the bash script, I get the following error in my terminal: 运行bash脚本时,在终端中出现以下错误:

XPath error : Undefined namespace prefix XPath错误:未定义的名称空间前缀

xmlXPathEval: evaluation failed xmlXPathEval:评估失败

XPath evaluation failure XPath评估失败

I'm not sure what the error means, nor do I know if I can run xmllint on a ".wsdl" file as I have with an ".xml" 我不确定错误的含义,也不知道是否可以像使用“ .xml”一样在“ .wsdl”文件上运行xmllint

Found the solution and it is to use xmlstarlet 找到了解决方案,它是使用xmlstarlet

More information can also be found in this answer 此答案中也可以找到更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM