xml 相关问题

可扩展标记语言(XML)是一种灵活的结构化文档格式,用于定义人类和机器可读的编码规则。

构建 XML feed 后对项目进行排序?

我在基于 XML 的 CMS(现代校园)工作。 XSLT 仍然是我试图即时学习的东西,所以我还不太熟悉这个领域。 我们的 CMS 正在构建一个博客提要(其中...

回答 1 投票 0

将 XML 表转换为 R 中的 tibble

我正在尝试将具有不同行数和列数的 XML 表转换为数据帧。我可以使用格式良好、可预测的表格来做到这一点,如下两个表格: ... 我正在尝试将具有不同行数和列数的 XML 表转换为数据帧。我可以使用格式良好、可预测的表格来做到这一点,就像这两个表格一样: <table xml:id="a"> <row role="label"> <cell cols="2">Stuff</cell> </row> <row> <cell>Thing</cell> <cell>1</cell> </row> <row> <cell>Another thing</cell> <cell>2</cell> </row> </table> <table xml:id="b"> <row role="label"> <cell cols="2">Nonsense</cell> </row> <row> <cell>Thing</cell> <cell>3</cell> </row> <row> <cell>Anything</cell> <cell>2</cell> </row> <row> <cell>Another thing</cell> <cell>2</cell> </row> </table> 我可以将它们更改为这样的小标题: # A tibble: 5 × 4 id label cell.1 cell.2 <chr> <chr> <chr> <dbl> 1 a Stuff Thing 1 2 a Stuff Another thing 2 3 b Nonsense Thing 3 4 b Nonsense Anything 2 5 b Nonsense Another thing 2 使用此代码: x <- "table.xml" file <- read_xml(x) cells <- file %>% xml_find_all(".//cell") output <- lapply(cells, function(d){ id <- d %>% xml_find_first(".//parent::row/parent::table")%>% xml_attr("id") label <- d %>% xml_find_first(".//parent::row/preceding-sibling::row[@role='label']")%>% xml_text() cell.1 <- d %>% xml_find_first(".//parent::row/cell")%>% xml_text() cell.2 <- d %>% xml_find_all(".//following-sibling::cell")%>% xml_double() tibble(id, label, cell.1, cell.2) }) answer <- do.call(rbind, output) 但是,这种方法依赖于提供的属性 (@role='label')、一致的单元格数量等。我需要在一堆格式不规则的 XML 表上运行此脚本。 如果我向上例中的某一行添加一个额外的单元格,我的方法就会失败。我怀疑我可能以错误的方式处理这个问题。例如,我可以用 xml2::as_list() 来做到这一点吗?我的尝试还没有成功。 这是一种使用 rvest 包和 tidyverse 转换中的 html_table 的可能方法。注意:您显示的 XML 无效。 ### Packages library(xml2) library(rvest) library(stringr) library(dplyr) library(purrr) ### Parse the XML and transform the result as character a=read_xml("C:/Users/YourName/Downloads/YourFile.xml") b=as.character(a) ### Replace the content of the XML to conform the tables to HTML tables structure b=str_replace_all(b,"cell cols","td colspan") b=str_replace_all(b,"row","tr") b=str_replace_all(b,"cell","td") ### Parse the result of the transformation c=read_xml(b) ### Get all ids of the tables attr=html_elements(c,xpath = "//table") %>% html_attrs() %>% unlist() ### Get all the tables temp=c%>% html_elements(xpath = "//table") %>% html_table() ### Declare a function to transform the tables ### Transform the last column from character to numeric transform=function(x,y){x %>% slice(-1) %>% mutate(id=y, label=x[1,1][[1]],.before=1, X2=as.numeric(X2))} ### Apply the function done=map2(.x = temp,.y = attr,.f = transform) ### Stack the tables and rename the columns end=bind_rows(gigachad) %>% rename_with(.fn = ~str_replace(.x,"X","cell."), .cols = starts_with("X")) 输出: # A tibble: 5 × 4 id label cell.1 cell.2 <chr> <chr> <chr> <dbl> 1 a Stuff Thing 1 2 a Stuff Another thing 2 3 b Nonsense Thing 3 4 b Nonsense Anything 2 5 b Nonsense Another thing 2

回答 1 投票 0

如何读取 XML 文件并解析它

我想知道如何使用ABAP读取xml文件,我在网上搜索过但没有找到足够清晰的答案。有人可以帮助我吗? 提前致谢, 沙米龙

回答 4 投票 0

为什么last()选择以下XML中的两个标签?

给出以下 XML: 嗨!这是 xpather 测试版... 这个网络应用程序使您能够查询 XML/HTML 文档...

回答 1 投票 0

SCCM 中缺少 XML 根元素

我遇到了一个问题,由于 XML 损坏,导致 SCCM 配置管理器控制台停止显示应用程序信息。 在互联网上查了一下,发现了以下内容......

回答 1 投票 0

如何使用 Ansible playbook 从 SOAP API 响应中获取标签值?

问题陈述 我们正在使用 Ansible 在 Windows 主机上运行 SOAP API 并尝试从 API 响应中获取值,但是,由于无效的 XPath 异常,我们无法获取值。 主要

回答 1 投票 0

使用ansible playbook运行时无法从soap api响应中获取标签值

问题陈述:我们正在使用ansible在Windows主机上运行soap-api并尝试从api响应中获取值,但是,由于无效的xpath异常,我们无法获取值。 ...

回答 1 投票 0

如何使用 XDocument 保留多行 XML 格式的属性?

我正在使用 XML 来编辑属性和值。我有一个这种格式的 XML 节点。 我正在使用 XML 来编辑属性和值。我有一个这种格式的 XML 节点。 <add attribute1="value" attribute2="ghjg" attribute3="ghjg" attribute4="ghjg" /> 更改保存值后,它会更改为 <add attribute1="value" attribute2="ghjg" attribute3="ghjg" attribute4="ghjg" /> 我尝试了 LoadOptions 和 SaveOptions,但没有一个起作用。 XDocument xmlFile = XDocument.Load(xmlCondigurationPath,LoadOptions.PreserveWhitespace); xmlFile.Save(xmlCondigurationPath,SaveOptions.DisableFormatting); 将 XmlWriter 与 XmlWriterSettings 一起使用。 var settings = new XmlWriterSettings { NewLineOnAttributes = true, Indent = true }; using var writer = XmlWriter.Create("test.xml", settings); xDocument.Save(writer);

回答 1 投票 0

XSLT 在输出到 DOM 时将 <image> 节点转换为 <img> 标签

现在是 2024 年,我正在做一个融合 XSLT 技术的项目。 我想出了一种简单的方法来访问 XML 文件,该文件正在使用 javascript 进行简单转换,但将其输出到 hi...

回答 1 投票 0

如何将 .nfo 文件转换为 .fff 文件

我有一个信息库文件,我想将其转换为 HTML。我正在尝试使用以下库对其进行转换:https://github.com/imazen/folioxml 它附带一个配置文件及其一部分

回答 2 投票 0

VB.Net 将简单的 xml 文件加载到 DataTable

我无法让 vb.net 将 xml 文件加载到数据表中以在 datagridview 和其他文本元素中使用。我已经尝试了过去 2 天能找到的大部分解决方案

回答 1 投票 0

具有空值的日期的 XML 反序列化

我从一个供应商处获取了一个 xml 文件,其中包含一些“空”日期,如下所示: 通过进行常规反序列化,它会失败: 内部异常:系统。

回答 2 投票 0

SOAP 的 PHP 数组/对象结构 (WSDL/wsse)

我必须了解如何使用 PHP 生成此示例 WSDL 的结构。 (SoapClient、SoapHeaders) 假设实际输出应该如下所示: 我必须了解如何使用 PHP 生成此示例 WSDL 的结构。 (SoapClient、SoapHeaders) 假设实际输出应该如下所示: <soapenv:Envelope xmlns="http://schemas.xmlsoap.org/1"> <soapenv:Header> <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/3"> <wsse:UsernameToken xmlns:wsu="http://schemas.xmlsoap.org/4"> <wsse:Username>name</wsse:Username> <wsse:Password Type="wsse:PasswordText">good_password</wsse:Password> <wsse:UsernameToken> </wsse:Security> </soapenv:Header> <soapenv:Body> <asi:ProcessMsg> <req:Payload> <req:Request> <req:Sub>DATA_1</req:Sub> <req:EID>DATA_2</req:EID> <req:IID>DATA_3</req:IID> <req:Customer FirstName="xxx" LastName="xxx"></req:Customer> <req:Lead LeadMaster="xxx" IntendedRepPer="xxx"></req:Lead> </req:Request> </req:Payload> </asi:ProcessMsg> </soapenv:Body> </soapenv:Envelope> 我尝试了三种不同的结构,但都不起作用 new \stdClass(); new \ArrayObject(); 数组() “new SoapHeader();”的结构 $Security = new \ArrayObject(); $Security['UsernameToken'] = new \ArrayObject(); $Security['UsernameToken']['Username'] = "name"; $Security['UsernameToken']['Password'] = "good_password"; // OR $Security = new \stdClass(); $Security->UsernameToken = new \stdClass(); $Security->UsernameToken->Username = "name"; $Security->UsernameToken->Password = "good_password"; $header = new SoapHeader('http://schemas.xmlsoap.org/ws/2002/07/secext','Security',$Security,false); $soapClient->__setSoapHeaders($header); “$soap_client->ServerMethod("Payload", $soap_request);”的结构: $soap_request = new \ArrayObject(); $soap_request['Payload'] = new \ArrayObject(); $soap_request['Payload']['Request'] = new \ArrayObject(); $soap_request['Payload']['Request']['Sub'] = "xxx"; $soap_request['Payload']['Request']['EID'] = "xxx"; $soap_request['Payload']['Request']['IID'] = "xxx"; $soap_request['Payload']['Request']['Customer'] = new \ArrayObject(); $soap_request['Payload']['Request']['Customer']['_'] = ''; $soap_request['Payload']['Request']['Lead'] = new \ArrayObject(); $soap_request['Payload']['Request']['Lead']['_'] = ''; foreach ($data['x'] as $key => $value) { $soap_request['Payload']['Request']['Customer'][$key] = $value; } foreach ($data['xx'] as $key => $value) { $soap_request['Payload']['Request']['Lead'][$key] = $value; } // OR $soap_request = new \stdClass(); $soap_request->Request = new \stdClass(); $soap_request->Request->Sub = "xxx"; $soap_request->Request->EID = "xxx"; $soap_request->Request->IID = "xxx"; $soap_request->Request->Customer = new \ArrayObject(); $soap_request->Request->Customer['_'] = ''; $soap_request->Request->Lead = new \ArrayObject(); $soap_request->Request->Lead['_'] = ''; foreach ($data['customer'] as $key => $value) { $soap_request->Request->Customer[$key] = $value; } foreach ($data['lead'] as $key => $value) { $soap_request->Request->Lead[$key] = $value; } 我尝试调试结构的事情: echo "FNs:\n" . $soapClient->__getFunctions() . "\n"; echo "REQUEST:\n" . $soapClient->__getLastRequest() . "\n"; echo "REQUEST (htmlent):\n" . htmlentities($soapClient->__getLastRequest()) . "\n"; 我遇到的错误消息: 输入格式不正确或不包含预期数据 调用 PropertySet.GetChild() 失败。 (该属性集没有任何子级。(SBL-EXL-00144)) 实际发送执行: $soap_response = $soapClient->ServerMethod($soap_request); 嗯,我现在真的陷入困境,不知道是否要搜索错误/错误,因为我没有任何“好的”详细错误需要调试。 这是我第一次必须使用 SOAP(将数据发送到服务),也许我完全错了?非常感谢您的帮助。 核心问题: php 内部的结构与所有命名空间是什么样子的, 属性,嵌套元素? 问题在于内置 PHP 函数 SoapHeader 需要提供广泛兼容的 SoapHeader。您可以通过扩展 PHP SoapHeader 类来查看实现。 我使用了 stdClass 对象作为有效负载。并通过将所有属性传递到最深的对象层来获取实际的数据字段。我希望通过我的问题的答案为某人节省一些研究。 安全肥皂头: namespace AppName\TheBundle\Services; use SoapHeader; use SoapVar; class AuthSoapHeaderHelper extends SoapHeader { private $wss_ns = 'http://schemas.xmlsoap.org/.../secext'; private $username = "username"; private $password = "good_password"; function __construct() { $auth = new \stdClass(); $auth->Username = new SoapVar($this->username, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns); $auth->Password = new SoapVar($this->password, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns); $username_token = new \stdClass(); $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns); $security_sv = new SoapVar( new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns), SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns); parent::__construct($this->wss_ns, 'Security', $security_sv, true); } } SOAP 有效负载: $soap_request = new \stdClass(); $soap_request->Payload = new \stdClass(); $soap_request->Payload->Request = new \stdClass(); $soap_request->Payload->Request->Sub = "DATA_1"; $soap_request->Payload->Request->EID = "DATA_2"; $soap_request->Payload->Request->IID = "DATA_3"; $soap_request->Payload->Request->Customer = new \stdClass(); $soap_request->Payload->Request->Lead = new \stdClass(); foreach ($data['x'] as $key => $value) { $soap_request->Payload->Request->Customer->{$key} = $value; } foreach ($data['xx'] as $key => $value) { $soap_request->Payload->Request->Lead->{$key} = $value; } 这导致了以下 wsdl/xml 结构: <soapenv:Envelope xmlns="http://schemas.xmlsoap.org/1"> <soapenv:Header> <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/3"> <wsse:UsernameToken xmlns:wsu="http://schemas.xmlsoap.org/4"> <wsse:Username>username</wsse:Username> <wsse:Password Type="wsse:PasswordText">good_password</wsse:Password> <wsse:UsernameToken> </wsse:Security> </soapenv:Header> <soapenv:Body> <asi:ProcessMsg> <req:Payload> <req:Request> <req:Sub>DATA_1</req:Sub> <req:EID>DATA_2</req:EID> <req:IID>DATA_3</req:IID> <req:Customer FirstName="xxx" LastName="xxx"></req:Customer> <req:Lead LeadMaster="xxx" IntendedRepPer="xxx"></req:Lead> </req:Request> </req:Payload> </asi:ProcessMsg> </soapenv:Body> </soapenv:Envelope>

回答 1 投票 0

按给定分数一次更改多个项目值

我必须管理电子目录,并且我需要更改它的价格值 按我的供应商给出的原始值的百分比。 xml文件具有这种结构,但是超过1000个项目...

回答 1 投票 0

如何根据API要求为不同的API添加策略

我正在编写 terraform 代码,同时也在编写 xml。我有两个 API 和不同的策略要求。我试图按照下面的代码实现它,但它没有帮助。有谁知道如何...

回答 1 投票 0

XSLT 循环嵌套数据

我嵌套了 xml 数据。我正在循环项目元素,并希望使用递归获得所有项目的价格总和。 <

回答 1 投票 0

如何正确使用ViewBinding创建父fragment?

我有大约 15 个片段,大部分使用相同的代码,我还为 ViewBinding 创建了一个有效的 BaseFragment,这样我就不需要每次都编写该部分。 不过还有其他的

回答 1 投票 0

如何使用c#循环遍历xml文档节点以使用xpath存储值

我正在尝试循环下面的 xml 文档 16 我正在尝试循环下面的 xml 文档 <proposer driverId="1"> <conviction convictionId="1"> <code>16</code> </conviction> <conviction convictionId="2"> <code>10</code> </conviction> </proposer> <driver driverId="2"> <conviction convictionId="3"> <code>22</code> </conviction> </driver> 我的想法是获取所有信念代码,无论是提议者还是驱动程序,并将其存储在字符串列表中,然后通过发送索引,我执行 elementAtDefault 来获取代码 DrivingConvictionCode1 = GetConvictionCode(1, risk), DrivingConvictionCode2 = GetConvictionCode(2, risk), DrivingConvictionCode3 = GetConvictionCode(3, risk), 在 GetConvictionCode 方法中,我将索引值与 XmlDoc 一起传递,并调用 GetConvictions 方法,然后执行 Elementatdefault 以基于索引获取 ConvictionCode private string GetConvictionCode(int convictionSrNo, XmlDocument risk) { var convictions = GetConvictions(risk); return convictions.ElementAtOrDefault(convictionSrNo - 1) == null ? string.Empty : convictions[convictionSrNo - 1]; } private List<string> GetConvictions(XmlDocument risk) { var convictions = new List<string>(); foreach (XmlNode selectNode in risk.SelectNodes("/risk/proposer/conviction")) { convictions.AddRange(new[] {selectNode.SelectSingleNode("/risk/proposer/conviction/code").InnerText}); } foreach (XmlNode selectNode in risk.SelectNodes("/risk/driver/conviction")) { convictions.AddRange(new[] {selectNode.SelectSingleNode("/risk/driver/conviction/code").InnerText}); } return convictions; } 我在这里面临的问题是在循环中下一个信念值正在被旧的值取代,所以如果第一次循环它是 16 下一次它应该是 10 但它来了 16。任何人都可以帮忙或告诉我任何其他方式 我期望的输出是 DrivingConvictionCode1 = GetConvictionCode(1, risk) > 16, DrivingConvictionCode2 = GetConvictionCode(2, risk) > 10, DrivingConvictionCode3 = GetConvictionCode(3, risk) > 22, 您应该使用 InnerText 而不是 .SelectSingleNode("<path>").InnerText 来获取值。 foreach (XmlNode selectNode in risk.SelectNodes("/risk/proposer/conviction")) { convictions.AddRange(new[] { selectNode.InnerText }); } foreach (XmlNode selectNode in risk.SelectNodes("/risk/driver/conviction")) { convictions.AddRange(new[] { selectNode.InnerText }); }

回答 1 投票 0

读取 JSON csv 和 xml

如何使用一个代码读取 JSON xml 和 csv 文件,或者最简单的方法是什么? 我尝试寻找一个示例或一段代码,让我知道从哪里开始,但没有找到。

回答 1 投票 0

通过 C# 访问时,<system.web> 为 null [重复]

我正在尝试从 web.config 获取以下超时值: ... ...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.