xml 相关问题

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

如何使用 Go 和 etree XML 包访问同级元素?

给定一个如下所示的 XML 文档: 今天 1 给定一个如下所示的 XML 文档: <MasterXML> <Processes> <Params> <ParamName>today</ParamName> <ParamType>1</ParamType> <ParamValue/> </Params> <Params> <ParamName>today</ParamName> <ParamType>2</ParamType> <ParamValue/> </Params> <Params> <ParamName>today</ParamName> <ParamType>3</ParamType> <ParamValue/> </Params> </Processes> </MasterXML> 使用 beevik/etree for Go 包,当 <ParamValue/> 具有特定的特定值时,如何访问文档中 <Params> 的每个实例的 <ParamName>,以用值填充它。 在给定的示例中,当 <ParamValue/> 持有值 today 时,我希望用 05/02/2024 填充所有 <Params> 节点中的所有 <ParamName> 节点。 此代码仅适用于包含许多实例的文档中 <Params> 节点的第一个实例,其中 <ParamName>== today ,尽管循环似乎应该访问 <Params> 的每个实例: for _, elem1 := range doc.FindElements(".//Processes//Params//ParamName") { if elem1 == nil { log.Fatal("Check XPath) } s := elem1.Text() if s == "today" { elem2 := elem1.FindElement("//ParamValue") elem2.SetText("05/02/2024") } } 我该怎么做?为什么 range doc.FindElements(".//Processes//Params//ParamName") 找不到 <Params> 的每个实例?我应该使用不同的方法吗? 您当前的代码确实按照您所描述的方式运行,因为通过在 XPath 中使用双斜杠,您始终以递归方式搜索 XML 树,这意味着您始终从顶部找到第一个出现的位置。 这是固定样本: package main import ( "log" "os" "strings" "github.com/beevik/etree" ) func main() { doc := etree.NewDocument() if err := doc.ReadFromFile("master.xml"); err != nil { panic(err) } for _, elem1 := range doc.FindElements(".//Processes//Params//ParamName") { if elem1 == nil { log.Fatal("Check XPath") } s := elem1.Text() //println(s) if strings.TrimSpace(s) == "today" { elem2 := elem1.FindElement("../ParamValue") elem2.SetText("05/02/2024") } } doc.WriteTo(os.Stdout) } 这需要 master.xml 与您的 .go 文件位于同一目录中。我选择了这个: <MasterXML> <Processes> <Params> <ParamName> today </ParamName> <ParamType>1</ParamType> <ParamValue/> </Params> <Params> <ParamName> tomorrow </ParamName> <ParamType>2</ParamType> <ParamValue/> </Params> <Params> <ParamName> today </ParamName> <ParamType>3</ParamType> <ParamValue/> </Params> </Processes> </MasterXML> 产生所需的输出: <MasterXML> <Processes> <Params> <ParamName> today </ParamName> <ParamType>1</ParamType> <ParamValue>05/02/2024</ParamValue> </Params> <Params> <ParamName> tomorrow </ParamName> <ParamType>2</ParamType> <ParamValue/> </Params> <Params> <ParamName> today </ParamName> <ParamType>3</ParamType> <ParamValue>05/02/2024</ParamValue> </Params> </Processes> </MasterXML>

回答 1 投票 0

转义字符串以在 XML 中使用

我正在使用 Python 的 xml.dom.minidom 创建 XML 文档。 (逻辑结构 -> XML 字符串,而不是相反。) 我如何让它转义我提供的字符串,这样他们就无法找到我......

回答 8 投票 0

在 SQL 中查询 XML 以返回 NULL 和空数据集的节点结果列表

我有一个包含一个 XML 列的 SQL 表,我想查询 XML 并获取 id/@extension 以及所有观察/代码的列表。但是它总是返回空结果。我已经隔离了一个考试...

回答 1 投票 0

Android 项目构建

引起:org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException:无法解析配置“:app:debugRuntimeClasspath”的所有文件。 我想要bui...

回答 1 投票 0

如何使用 PHP 读取带有 HTML 标签的 XML?

我已经多次使用 php 和 XML,但这种 XML 在开头和结尾都有 Html 标签: 链接到 XML 没有到 xml 文件的直接链接,所以我必须使用

回答 2 投票 0

在 xml 响应中链接到 php 变量[重复]

我从连接脚本中链接得到这个结果, [email protected] http://m3.licdn.com/mpr/mprx/

回答 3 投票 0

如何将 R 中的分层节点数据转换为数据框?

我有以下 xml 文件。 我有以下 xml 文件。 <?xml version="1.0" encoding="UTF-8"?> <gudid xmlns="http://www.fda.gov/cdrh/gudid" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation="http://www.fda.gov/cdrh/gudid gudid.xsd"> <header> <database frequency="monthly" id="5460" type="FULL"> <downloadFile part="1" totalParts="174"/> <numberRecordXML>25000</numberRecordXML> <numberRecordsDatabase>4334252</numberRecordsDatabase> </database> <creationDate>2024-04-01T03:30:00</creationDate> <period end="2024-04-01T03:30:00" start="2014-09-24T00:00:00"/> </header> <device xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.fda.gov/cdrh/gudid"> <publicDeviceRecordKey>33db3dc9-1c5e-4670-a3e1-b52ae0e8c7f0</publicDeviceRecordKey> <publicVersionStatus>Update</publicVersionStatus> <deviceRecordStatus>Published</deviceRecordStatus> <!--Note: publicVersionNumber is system generated and assigned to all device records to track public release updates to a device record--> <publicVersionNumber>3</publicVersionNumber> <publicVersionDate>2018-07-06</publicVersionDate> <devicePublishDate>2016-09-01</devicePublishDate> <deviceCommDistributionEndDate xsi:nil="true"></deviceCommDistributionEndDate> <deviceCommDistributionStatus>In Commercial Distribution</deviceCommDistributionStatus> <identifiers> <identifier> <deviceId>M991NM82330A243</deviceId> <deviceIdType>Package</deviceIdType> <deviceIdIssuingAgency>HIBCC</deviceIdIssuingAgency> <containsDINumber>M991NM82330A242</containsDINumber> <pkgQuantity>4</pkgQuantity> <pkgDiscontinueDate xsi:nil="true"></pkgDiscontinueDate> <pkgStatus>In Commercial Distribution</pkgStatus> <pkgType>Case</pkgType> </identifier> <identifier> <deviceId>M991NM82330A242</deviceId> <deviceIdType>Package</deviceIdType> <deviceIdIssuingAgency>HIBCC</deviceIdIssuingAgency> <containsDINumber>M991NM82330A241</containsDINumber> <pkgQuantity>8</pkgQuantity> <pkgDiscontinueDate xsi:nil="true"></pkgDiscontinueDate> <pkgStatus>In Commercial Distribution</pkgStatus> <pkgType>Box</pkgType> </identifier> <identifier> <deviceId>M991NM82330A241</deviceId> <deviceIdType>Primary</deviceIdType> <deviceIdIssuingAgency>HIBCC</deviceIdIssuingAgency> <containsDINumber xsi:nil="true"></containsDINumber> <pkgQuantity xsi:nil="true"></pkgQuantity> <pkgDiscontinueDate xsi:nil="true"></pkgDiscontinueDate> <pkgStatus xsi:nil="true"></pkgStatus> <pkgType xsi:nil="true"></pkgType> </identifier> </identifiers> <brandName>Clear-View MAX &quot;Sub-Q&quot; Infusion Set</brandName> <versionModelNumber>ClearView™MAX</versionModelNumber> <catalogNumber>NM82330A-24</catalogNumber> <dunsNumber>013861471</dunsNumber> <companyName>NORFOLK MEDICAL</companyName> <deviceCount>1</deviceCount> <deviceDescription>24G x 12mm x 24&quot; Clear-View MAX &quot;Sub-Q&quot; Infusion Set</deviceDescription> <DMExempt>true</DMExempt> <premarketExempt>false</premarketExempt> <deviceHCTP>false</deviceHCTP> <deviceKit>false</deviceKit> <deviceCombinationProduct>false</deviceCombinationProduct> <singleUse>true</singleUse> <lotBatch>true</lotBatch> <serialNumber>false</serialNumber> <manufacturingDate>true</manufacturingDate> <expirationDate>true</expirationDate> <donationIdNumber>false</donationIdNumber> <labeledContainsNRL>false</labeledContainsNRL> <labeledNoNRL>true</labeledNoNRL> <MRISafetyStatus>Labeling does not contain MRI Safety Information</MRISafetyStatus> <rx>true</rx> <otc>false</otc> <contacts> <customerContact> <phone>+1(847)674-7075</phone> <phoneExtension>102</phoneExtension> <email>[email protected]</email> </customerContact> </contacts> <premarketSubmissions> <premarketSubmission> <submissionNumber>K870188</submissionNumber> <supplementNumber>000</supplementNumber> </premarketSubmission> </premarketSubmissions> <gmdnTerms> <gmdn> <gmdnCode>35833</gmdnCode> <gmdnPTName>Electric infusion pump administration set, single-use</gmdnPTName> <gmdnPTDefinition>A collection of sterile devices (e.g., plastic tubing, check valve, roller clamp, Y-site connector, Luer, needle/catheter) intended to be used in combination with an electrically-powered infusion pump for the intravenous (IV), subcutaneous, intramuscular, or epidural administration of medication. This is a single-use device.</gmdnPTDefinition> <implantable>false</implantable> <gmdnCodeStatus>Active</gmdnCodeStatus> </gmdn> </gmdnTerms> <productCodes> <fdaProductCode> <productCode>FPA</productCode> <productCodeName>Set, administration, intravascular</productCodeName> </fdaProductCode> </productCodes> <deviceSizes> <deviceSize> <sizeType>Needle Gauge</sizeType> <size value="24" unit="Gauge"/> <sizeText xsi:nil="true"></sizeText> </deviceSize> </deviceSizes> <environmentalConditions/> <sterilization> <deviceSterile>true</deviceSterile> <sterilizationPriorToUse>true</sterilizationPriorToUse> <methodTypes> <sterilizationMethod>Ethylene Oxide</sterilizationMethod> </methodTypes> </sterilization> </device> </gudid> 我想将其转换为数据框。标识符具有层次结构并且存在三个标识符。我编写的代码如下,但在这种情况下,所有标识符都放在标识符列的一个单元格中,导致无法区分这些值。 setwd('D:/') doc <- read_xml('xmltest.xml') xml <- xmlParse(doc) df <- xmlToDataFrame(xml) 此外,我只想将设备节点转换为数据帧,而头节点保持不变。 这里是一个使用 jsonlite 库将列表转换为数据框的 around 方法。 library(xml2) library(jsonlite) page <- read_xml('xmltest.xml' ) #strip the names spaces xml_ns_strip(page) #convert to a list and then use json lite library to covert into a data frame xml_find_all(page, ".//identifier") %>% as_list() %>% jsonlite::toJSON() %>% jsonlite::fromJSON(simplifyDataFrame = TRUE)

回答 1 投票 0

ViewPager下如何设置TabLayout?

我在LinearLayout中有TabLayout和ViewPager2: 我在 LinearLayout 中有 TabLayout 和 ViewPager2: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <com.google.android.material.tabs.TabLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/main_tabLayout"/> <androidx.viewpager2.widget.ViewPager2 android:layout_width="match_parent" android:layout_height="0dp" android:id="@+id/view_pager" android:layout_weight="1"/> </LinearLayout> 它工作正常,但我需要 ViewPager 下的 TabLayout。如果我交换它们,TabLayout 不会显示(ViewPager 可见并且工作正常)。 ViewPager下如何设置TabLayout? 我试过了 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.viewpager2.widget.ViewPager2 android:layout_width="match_parent" android:layout_height="0dp" android:id="@+id/view_pager" android:layout_weight="1"/> <com.google.android.material.tabs.TabLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/main_tabLayout"/> </LinearLayout> 在这种情况下,只有 ViewPager 可见 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.viewpager2.widget.ViewPager2 android:layout_width="match_parent" android:layout_height="0dp" android:id="@+id/view_pager" android:layout_weight="1" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toTopOf="@id/main_tabLayout" /> <com.google.android.material.tabs.TabLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/main_tabLayout" android:visibility="visible" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> 尝试使用这个布局。希望它会起作用。

回答 1 投票 0

从流输入中解析没有根元素的 XML 片段列表

在 Java 中使用 SAX api 解析流输入中没有根元素的 XML 片段列表是否可行? 我尝试解析这样的 XML 但得到了 org.xml.sax.SAXParseException:标记...

回答 2 投票 0

将 xml 读入 LINQ 格式以检查日志文件数据 - 列表格式的条件 - linq 未拾取重新格式化的 xml

我有一个项目,它读取每个构建区域的预期构建结果的 xml,并与构建日志进行比较以查看构建是否通过。现在,linq 在单独的

回答 1 投票 0

如何检测丢失的文件而不抛出错误

我提到了xsl中的xml文件路径,但我想暂时删除文件夹中的那个xml文件,并且我总是想保留在xsl中。但是当我删除它时显示警告。 我提到了xsl中的xml文件路径,但我想暂时删除文件夹中的那个xml文件,并且我总是想保留在xsl中。但是当我删除它时显示警告。 <xsl:apply-templates mode="replaceVariables" select="document('../Folder_1/Test.xml')"> </xsl:apply-templates> 我从Test.xml中删除了Folder_1。当我运行时,出现以下错误 Engine name: Saxon-PE 9.9.1.7 Severity: warning Description: I/O error reported by XML parser processing file:/C:/Work/Folder_1/Test.xml: C:/Work/Folder_1/Test.xml (The system cannot find the file specified) Start location: 674:48 Length: 1 即使 xml 文件在相应的提到的文件夹中删除,它在转换时也不应该显示错误。 在 XSLT 2.0 及更高版本中,有 XPath 2.0 及更高版本的函数 doc-available 例如doc-available('../Folder_1/Test.xml'),因此您可以在 xsl:if 周围使用 xsl:apply-templates 检查,或者您甚至可以在 select 表达式的谓词中使用该检查。

回答 1 投票 0

文件夹文件不可用,正在经历错误

我提到了xsl中的xml文件路径,但我想暂时删除文件夹中的那个xml文件,并且我总是想保留在xsl中。但是当我删除它时显示警告。 我提到了xsl中的xml文件路径,但我想暂时删除文件夹中的那个xml文件,并且我总是想保留在xsl中。但是当我删除它时显示警告。 <xsl:apply-templates mode="replaceVariables" select="document('../Folder_1/Test.xml')"> </xsl:apply-templates> 我从Test.xml中删除了Folder_1。当我运行时,出现以下错误 Engine name: Saxon-PE 9.9.1.7 Severity: warning Description: I/O error reported by XML parser processing file:/C:/Work/Folder_1/Test.xml: C:/Work/Folder_1/Test.xml (The system cannot find the file specified) Start location: 674:48 Length: 1 即使 xml 文件在相应的提到的文件夹中删除,它在转换时也不应该显示错误。 在 XSLT 2.0 及更高版本中,有 XPath 2.0 及更高版本的函数 doc-available 例如doc-available('../Folder_1/Test.xml'),因此您可以在 xsl:if 周围使用 xsl:apply-templates 检查,或者您甚至可以在 select 表达式的谓词中使用该检查。

回答 1 投票 0

Android - PhoneGap 错误:解析 XML 时出错:未绑定前缀

我重新启动了eclipse,错误在同一行改为“error: Error parsing XML: unbound prefix” 我正在尝试在我的 Android PhoneGap 应用程序中使用这个插件。这是本地人

回答 3 投票 0

cURL 命令中的 -d 是什么意思?

cURL 的 -d 是什么意思? 我有一个 RESTful API,只有 cURL 文档。 但我不能使用cURL命令,所以我需要翻译。 这是一个例子: 卷曲 -u '{userEmail}:{userApiToken}' -v ...

回答 1 投票 0

计算输入xml中唯一字段的数量

我想获取以下 xml 中唯一的“id”字段。 测试配置文件订单 11 ...

回答 1 投票 0

从 SQL Server 中的动态 XML 层次结构导出数据

我想获取动态 XML 文件中层次结构中的最低值。 我尝试编写一个动态表达式来读取 XML 文件: patdata.value('(*[本地名称() = sql:column("DataMng.Root&...

回答 1 投票 0

如何在SQL中查询XML并返回所有节点的列表

我有一个包含一个 XML 列的 SQL 表,我想查询 XML 并获取 id/@extension 以及所有观察/代码的列表。但是它总是返回空结果。我已经隔离了一个考试...

回答 1 投票 0

我的代码无法读取 xml 文件。代码有错误吗

[这是我收到的错误](https://i.sstatic.net/3DUyRhlD.png) 路径 = glob('/Users/ayeshanasim/Desktop/Major Project/*.xml') labels_dict = dict(文件路径=[], xmin=[], xmax=[], ymin=[], ym...

回答 1 投票 0

如何在 MyBatis Mapper XML 中连接 ResultHandler

我找到了几个如何将自定义 ResultHandler 连接到 MyBatis 查询的示例: 例如https://code.google.com/p/mybatis/wiki/ResultHandlerExample 不幸的是前文中给出的 ResultHandler...

回答 2 投票 0

获取 Java Web Servlet 的 ClassNotFound 错误

应用程序在Tomcat Web服务器上顺利运行。 每当我尝试访问此 java web servlet URL/prepare_ payment 时,我都会收到以下错误: 严重:为 servlet 分配异常 [Servlet

回答 1 投票 0

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