xml 相关问题

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

错误:找不到符号View root = inflater.inflate(R.layout.toolbar,parent,false);

我使用数据绑定来连接UI,但是当我重建项目时,出现以下错误: 错误:找不到符号 View root = inflater.inflate(R.layout.toolbar, Parent, false); ...

回答 1 投票 0

我无法删除 android studio 中导航视图图标下方的空间。代码有什么问题吗?

我包括我的代码供您参考,还有应用程序启动时的屏幕。 我提供了我的代码供您参考,还有应用程序启动时的屏幕。 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="bottom" android:orientation="vertical" android:padding="0dp" tools:context=".dashboard"> <com.google.android.material.bottomnavigation.BottomNavigationView android:layout_width="match_parent" android:layout_height="60dp" android:background="#6000BCD4" android:padding="0dp" app:itemIconSize="20dp" app:itemPaddingBottom="0dp" app:itemPaddingTop="0dp" app:menu="@menu/bottom_nav_value" /> </LinearLayout> 我想删除导航视图图标下方的额外间距。 使用下面的代码并使用相对布局而不是线性布局。 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent"> <com.google.android.material.bottomnavigation.BottomNavigationView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/nav_view" android:background="#6000BCD4" app:elevation="4dp" app:labelVisibilityMode="auto" app:itemHorizontalTranslationEnabled = "false" android:layout_alignParentBottom="true" app:itemIconSize="23sp" app:menu="@menu/bottom_nav_menu"/> </RelativeLayout>

回答 1 投票 0

使用可选的不同名称反序列化 XML

我有这个类的定义 公共课 Foo { } 反序列化为这个 xml 我有这个类的定义 public class Foo { } 反序列化到这个 xml 中 <?xml version="1.0"?> <Foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> </Foo> 此 xml 文件布局已存在于客户端计算机上。 我想将班级从 Foo 重命名为 Footastic。 public class Footastic { } 现在称为类 Footastic 的任何新序列化,都应序列化为 <?xml version="1.0"?> <Footastic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> </Footastic> 我的问题是如何告诉反序列化接受Foo或Footastic? 我知道我可以通过指定 Footastic 属性将 Foo“重命名”为 XmlRoot。 [XmlRoot("Foo")] public class Footastic { } 但这也会改变对象的任何新序列化,这是不希望的。 新的序列化应序列化为 Footastic 反序列化时仅支持包含旧名称 Foo 的旧 xml 文件。以防万一您需要反序列化/序列化的代码。我真的没有做任何花哨的事情。 反序列化: Footastic 序列化: public static T? Deserialize<T>(string fileName) { if (!File.Exists(fileName)) return default; using FileStream streamReader = new(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); using var xr = XmlReader.Create(streamReader); XmlSerializer xmlDeSerializer = new(typeof(T)); return (T?)xmlDeSerializer.Deserialize(xr); } 尝试以下方法。 创建一个自定义 XML 阅读器,即时将名称 public static void Serialize<T>(T? value, string fileName) { if (value is null) return; Directory.CreateDirectory(Path.GetDirectoryName(fileName) ?? ""); using FileStream fileStream = new(fileName, FileMode.Create, FileAccess.Write, FileShare.Write); using var streamWriter = XmlWriter.Create(fileStream, new() { Encoding = Encoding.UTF8, Indent = true }); XmlSerializer xmlSerializer = new(typeof(T)); xmlSerializer.Serialize(streamWriter, value); } 替换为 Foo。Footastic 像这样使用它。 public class FooReader : XmlTextReader { // Add other constructor overloads as needed. public FooReader(string url) : base(url) { } public override string LocalName { get { if (base.LocalName == "Foo") return "Footastic"; return base.LocalName; } } } 这将接受 var ser = new XmlSerializer(typeof(Footastic)); using var fooReader = new FooReader("test.xml"); var foo = (Footastic)ser.Deserialize(fooReader); 和 Foo。不过,要小心!这将替换所有 Foo 元素! 如果其他地方的 xml 中存在同名元素,那么您需要进行额外的检查。

回答 1 投票 0

如何使用 yq 解析 XML?

嗨,我想使用 yq 解析服务器名称,问题是每次我都必须指定每个服务器的索引,如果这是一种在不指定的情况下获取服务器名称的方法...

回答 1 投票 0

使用 python 从 xml 中检索标签

我在employeedata.xml 文件中有员工数据。我的样本数据如下所示 <_x005B_dbo_x00...

回答 1 投票 0

PHP - SimpleXMLElement 未使用名称空间正确解析

这是由API返回的: 这是由 API 返回的: <?xml version='1.0' encoding='utf-8'?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="https://exmple.com/odata/"> <id>https://example.com/odata/PicklistOption(989L)</id> <title type="text" /> <updated>2015-09-03T11:56:51Z</updated> <author> <name /> </author> <link rel="edit" title="PicklistOption" href="PicklistOption(989L)" /> <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/childPicklistOptions" type="application/atom+xml;type=feed" title="childPicklistOptions" href="PicklistOption(989L)/childPicklistOptions" /> <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/parentPicklistOption" type="application/atom+xml;type=entry" title="parentPicklistOption" href="PicklistOption(989L)/parentPicklistOption" /> <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/picklistLabels" type="application/atom+xml;type=feed" title="picklistLabels" href="PicklistOption(989L)/picklistLabels" /> <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/picklist" type="application/atom+xml;type=entry" title="picklist" href="PicklistOption(989L)/picklist" /> <category term="SFOData.PicklistOption" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> <content type="application/xml"> <m:properties> <d:id m:type="Edm.Int64">989</d:id> <d:status>ACTIVE</d:status> <d:sortOrder m:type="Edm.Int32">229</d:sortOrder> <d:minValue m:type="Edm.Double">-1</d:minValue> <d:externalCode>PL</d:externalCode> <d:optionValue m:type="Edm.Double">-1</d:optionValue> <d:maxValue m:type="Edm.Double">-1</d:maxValue> </m:properties> </content> </entry> 现在正在努力获得<d:id> $xml = new SimpleXMLElement($xmlstr); $namespaces = $xml->getNameSpaces(true); $xml->registerXPathNamespace('m', $namespaces['m']); $xml->registerXPathNamespace('d', $namespaces['d']); $id = $xml->xpath('/entry/content/m:properties/d:id'); var_dump($id); 但我明白了array(0)。 不要从文档中获取命名空间。在您的应用程序中定义它们。命名空间是 xmlns/xmlns:* 属性的值。 xmlns 属性是默认命名空间。所以标签 entry 实际上是 {http://www.w3.org/2005/Atom}:entry。 命名空间必须是唯一的。为了避免冲突,大多数人使用 URL。 (其他人不太可能使用您的域来定义他们的命名空间。)这样做的缺点是命名空间是带有特殊字符的大字符串。这是通过使用命名空间前缀作为别名来解决的。 Xpath 没有默认的命名空间。您需要为您喜欢使用的每个命名空间注册一个前缀。 Xpath 引擎会将前缀解析为实际名称空间,并将其与节点解析的名称空间进行比较。 $xml = new SimpleXMLElement($xmlstr); $namespaces = [ 'a' => 'http://www.w3.org/2005/Atom', 'm' => 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata', 'd' => 'http://schemas.microsoft.com/ado/2007/08/dataservices', 'o' => 'https://exmple.com/odata/' ]; foreach ($namespaces as $prefix => $namespace) { $xml->registerXPathNamespace($prefix, $namespace); } $id = $xml->xpath('/a:entry/a:content/m:properties/d:id'); var_dump($id); 输出: array(1) { [0]=> object(SimpleXMLElement)#2 (0) { } } 您必须再次在每个 SimpleXMLElement 上注册 Xpath 命名空间。 这在 DOM 中更方便。 DOMXpath::evaluate() 执行 Xpath 表达式,并可以返回节点列表或标量,具体取决于表达式。 $document = new DOMDocument($xmlstr); $document->loadXml($xmlstr); $xpath = new DOMXpath($document); $namespaces = [ 'a' => 'http://www.w3.org/2005/Atom', 'm' => 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata', 'd' => 'http://schemas.microsoft.com/ado/2007/08/dataservices', 'o' => 'https://exmple.com/odata/' ]; foreach ($namespaces as $prefix => $namespace) { $xpath->registerNamespace($prefix, $namespace); } $id = $xpath->evaluate('string(/a:entry/a:content/m:properties/d:id)'); var_dump($id); 输出: string(3) "989" 这是如何通过节点元素方法完成的,例如 $xml->内容->属性->id ?

回答 2 投票 0

尝试在 Ebay 中发布列表时出现问题

关于 我正在尝试在 Ebay 交易 API 中发布列表。我们可以看到,这里的 Ebay API 文档提到了品牌信息:https://developer.ebay.com/devzone/xml/docs/Reference...

回答 1 投票 0

从xml获取属性并打印错误

我正在尝试使用 C# 和 linq 从 xml 中检索属性值。打印时属性数据为空。任何帮助将不胜感激。除了检索属性值...

回答 1 投票 0

我无法滚动到页面末尾。安卓工作室

我无法滚动到页面末尾。 这是我的 xml 代码: 我无法滚动到页面末尾。 这是我的 xml 代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".UploadActivity"> <ImageButton android:id="@+id/uploadButton_close" android:layout_width="25dp" android:layout_height="26dp" android:layout_marginStart="20dp" android:layout_marginBottom="84dp" android:layout_marginTop="10dp" android:background="@android:color/transparent" android:scaleType="fitCenter" app:srcCompat="@drawable/close_icon" /> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <androidx.cardview.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dp" android:layout_marginEnd="20dp" android:layout_marginStart="20dp" app:cardCornerRadius="30dp" app:cardElevation="20dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:layout_gravity="center_horizontal" android:padding="20dp" android:background="@drawable/lavender_border"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Завантажте дані" android:textSize="30sp" android:textAlignment="center" android:textColor="@color/purple" /> <ImageView android:id="@+id/uploadImage" android:layout_width="match_parent" android:layout_height="200dp" android:scaleType="fitCenter" android:src="@drawable/baseline_image_search_24" android:layout_marginTop="10dp" /> <EditText android:layout_width="match_parent" android:layout_height="60dp" android:id="@+id/uploadTitle" android:textSize="16sp" android:textStyle="bold" android:background="@drawable/lavender_border" android:hint="Введіть заголовок" android:layout_marginTop="20dp" android:padding="16dp" android:layout_gravity="start|center_vertical" android:textColor="@color/purple"/> <EditText android:layout_width="match_parent" android:layout_height="60dp" android:id="@+id/uploadCaption" android:textSize="14sp" android:background="@drawable/lavender_border" android:hint="Введіть короткий опис" android:layout_marginTop="20dp" android:padding="16dp" android:layout_gravity="start|center_vertical" android:textColor="@color/purple"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/uploadText" android:background="@drawable/lavender_border" android:hint="Введіть текст" android:textSize="14sp" android:layout_marginTop="20dp" android:padding="16dp" android:layout_gravity="start|center_vertical" android:textColor="@color/purple" android:inputType="textMultiLine" android:minLines="12" android:gravity="top" /> <EditText android:layout_width="match_parent" android:layout_height="60dp" android:id="@+id/uploadLink" android:textSize="14sp" android:background="@drawable/lavender_border" android:hint="Посилання" android:layout_marginTop="20dp" android:padding="16dp" android:layout_gravity="start|center_vertical" android:textColor="@color/purple"/> <AutoCompleteTextView android:id="@+id/uploadTheme" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="start|center_vertical" android:layout_marginTop="20dp" android:background="@drawable/lavender_border" android:hint="Оберіть тему" android:inputType="none" android:padding="16dp" android:textColor="@color/purple" android:textSize="14sp" tools:ignore="SpeakableTextPresentCheck" android:drawableEnd="@drawable/baseline_arrow_drop_down_24"/> <Button android:layout_width="match_parent" android:layout_height="60dp" android:text="Зберегти" android:id="@+id/uploadButton_save" android:textSize="18sp" android:layout_marginTop="10dp" /> </LinearLayout> </androidx.cardview.widget.CardView> </ScrollView> </RelativeLayout> 如何解决?感谢您的回复。 我尝试添加更多 margin_bottom 但它不起作用,我也删除了它,尝试添加填充等。 如果我将 margin_bottom 添加到 LinearLayout,CardView 会超越 如果我将 margin_bottom 添加到 CardView,则不会发生任何事情。我还尝试更改 match_parent/wrap_content 的布局高度,但没有任何帮助。 从 LinearLayout 中删除内边距,按钮将不再在底部被切断。删除这个:android:padding="20dp" 您正在用所有其他视图的高度填充屏幕,没有空间进行填充。

回答 1 投票 0

OpenTimelineIO FCP XML 导入无法找到剪辑

我在 Final Cut Pro 和 Adobe Premiere 中有几个视频项目想要转换为 Kdenlive。我找到了 OpenTimelineIO,并通过反复试验并感谢 StackOverflow,得到了以下代码:

回答 1 投票 0

XPath - 如何从子节点中排除文本

我想要这个输出(示例): 我要这个 我正在处理 XML/TEI 文档,我需要使用 XPath 表达式,并且我希望将 div/u 中的文本作为输出,但没有节点 e 内的文本...

回答 2 投票 0

根据文件.XLM上的参数批量重命名.pdf

我想帮助我的会计同事,他们从门户网站下载多个以一堆数字命名的.pdf文件,然后按照如下格式手动重命名:

回答 1 投票 0

如何从表中的 XML 列获取所有 XML 路径的超集

我有一个带有 XML 列的表。我没有该列的数据字典或 XML 结构的定义。大约有 150 万条记录。通过对小样本的目视检查,

回答 1 投票 0

XSLT 2.0 中的链接模板

我有一个非常简单的输入文件: ...

回答 1 投票 0

如何在 Eclipse 中设置 Maven POM 编辑器的格式设置?

当我使用 Maven POM 编辑器打开 pom.xml 并尝试使用默认快捷键 ctrl + shift + f 进行格式化时,我希望该文件被格式化为具有 Preferen 中配置的规则的任何其他 .xml...

回答 1 投票 0

使用 nodeJS 中的参数和 saxon-js 将 XSLT 重用于不同的 XML 输入

我想使用 XSLT 将未知数量的不同但非常相似的结构化输入 XML 文档转换为单个输出 XML 格式。 我的平台是node.js,因此我正在研究...

回答 1 投票 0

如何使用python脚本将xml文件转换为csv

我有一个具有特殊结构的xml文件,我需要使用脚本python将其转换为csv文件 这是我的 xml 文件的一部分: 我有一个具有特殊结构的 xml 文件,我需要使用脚本 python 将其转换为 csv 文件 这是我的 xml 文件的一部分: <?xml version="1.0" encoding="UTF-8"?> <results version="2"> <cppcheck version="2.9"/> <errors> <error identifier="redundantAssignment" errorStyle="style" msg="Variable &apos;ret&apos; is reassigned a value before the old one has been used."> <location file="D:\test\main.c" line="64" column="8" info="ret is overwritten"/> <location file="D:\test\main.c" line="62" column="8" info="ret is assigned"/> <symbol>ret</symbol> </error> <error identifier="redundantAssignment" errorStyle="style" msg="Variable &apos;ret&apos; is reassigned a value before the old one has been used."> <location file="D:\test\data.c" line="93" column="8" info="ret is overwritten"/> <location file="D:\test\data.c" line="91" column="8" info="ret is assigned"/> <symbol>ret</symbol> </error> </errors> </results> 我正在使用这个脚本,但它对我不起作用: import xml.etree.ElementTree as ET import csv # PARSE XML xml = ET.parse("./error.xml") root = xml.getElementsByTagName() # CREATE CSV FILE csvfile = open("data.csv",'w',encoding='utf-8') csvfile_writer = csv.writer(csvfile) # ADD THE HEADER TO CSV FILE csvfile_writer.writerow(["identifier","file","errorStyle","msg"]) # FOR EACH EMPLOYEE for error in root.findall("errors/error"): if(error): # EXTRACT EMPLOYEE DETAILS identifier = error.get('identifier') file = error.find('file') errorStyle = error.find("errorStyle") msg = error.find("msg") csv_line = [identifier, file.text, errorStyle.text, msg.text] # ADD A NEW ROW TO CSV FILE csvfile_writer.writerow(csv_line) csvfile.close() 请参考以下代码: import xml.etree.ElementTree as ET import csv xml_data = """<?xml version="1.0" encoding="UTF-8"?> <results version="2"> <cppcheck version="2.9"/> <errors> <error identifier="redundantAssignment" errorStyle="style" msg="Variable &apos;ret&apos; is reassigned a value before the old one has been used."> <location file="Din.c" line="64" column="8" info="ret is overwritten"/> <location file="D.c" line="62" column="8" info="ret is assigned"/> <symbol>ret</symbol> </error> <error identifier="redundantAssignment" errorStyle="style" msg="Variable &apos;ret&apos; is reassigned a value before the old one has been used."> <location file="Dta.c" line="93" column="8" info="ret is overwritten"/> <location file="Dta.c" line="91" column="8" info="ret is assigned"/> <symbol>ret</symbol> </error> </errors> </results>""" root = ET.fromstring(xml_data) csvfile = open("data.csv",'w') csvfile_writer = csv.writer(csvfile) csvfile_writer.writerow(["msg","identifier","errorStyle"]) for child in root: for item in child: csv_line = [item.attrib["msg"],item.attrib["identifier"] , item.attrib["errorStyle"]] csvfile_writer.writerow(csv_line) print item.attrib csvfile.close() 希望这有帮助,谢谢。 注意:不是原始问题的答案,而是一个有价值的示例,具体取决于 xml 结构: 我在使用 csv 和 pandas 模块强制 csv 输出为文本字段时遇到了麻烦。 (没有引号或三引号) 当您有一个相当简单的 xml,您只想将属性或子元素转换为 csv 时,我想出了一个仅包含简单文件 IO、格式化程序和生成器表达式的解决方案: import os import xml.etree.ElementTree as ET def items2csv(root, csv_path): attributes = ['name', 'gps', 'country', 'year', 'notes'] csvfile = open(csv_path, 'w') # Column headers line = '"{}", "{}", "{}", "{}", "{}"'.format(*attributes) csvfile.write(line) for parent in root: values = [(parent.get(attrib) if parent.get(attrib) != None else '') for attrib in attributes] line = '\n"{}", "{}", "{}", "{}", "{}"'.format(*values) csvfile.write(line) csvfile.close() xml_data = """<?xml version="1.0" encoding="UTF-8"?> <tree> <item name="Name1" gps="24.227191 35.573413" country="Egypt" year="2004"></item> <item name="Name2" gps="24.228596 35.573733" country="Egypt" year="2004"></item> <item name="Name3" gps="24.253222 35.539939" country="Egypt" year="2004"></item> <item name="Name4" gps="25.429583 34.694408" country="Egypt" year="2007" notes="https://www.blabla.com "></item> <item name="Name5" gps="25.309756 34.860375" country="Egypt" year="2007"></item> </tree>""" #root = ET.parse('test.xml').getroot() # from file root = ET.fromstring(xml_data) # from variable items2csv(root, os.path.dirname(__file__) + "/test_output.csv") wait = input("Press Enter to Exit.") 以及基于子元素的简单 xml 结构的示例: #!/usr/bin/python import os import xml.etree.ElementTree as ET def items2csv(root, csv_path): tags = ['name', 'gps', 'country', 'year', 'notes'] csvfile = open(csv_path, 'w') # Column headers line = '"{}", "{}", "{}", "{}", "{}"'.format(*tags) csvfile.write(line) for parent in root: values = [(parent.findtext(tag) if parent.findtext(tag) != None else '') for tag in tags] line = '\n"{}", "{}", "{}", "{}", "{}"'.format(*values) csvfile.write(line) csvfile.close() xml_data = """<?xml version="1.0" encoding="UTF-8"?> <tree> <item> <name>Name1</name> <gps>24.227191 35.573413</gps> <country>Egypt</country> <year>2004</year> </item> <item> <name>Name2</name> <gps>24.228596 35.573733</gps> <country>Egypt</country> <year>2004</year> </item> <item> <name>Name3</name> <gps>24.253222 35.539939</gps> <country>Egypt</country> <year>2004</year> </item> <item> <name>Name4</name> <gps>25.429583 34.694408</gps> <country>Egypt</country> <year>2007</year> <notes>https://www.blabla.com</notes> </item> <item> <name>Name5</name> <gps>25.309756 34.860375</gps> <country>Egypt</country> <year>2007</year> </item> </tree>""" #root = ET.parse('test.xml').getroot() # from file root = ET.fromstring(xml_data) # from variable items2csv(root, os.path.dirname(__file__) + "/test_output.csv") wait = input("Press Enter to Exit.")

回答 2 投票 0

从 VBA 编写 xml

我编写了一个 VBA 脚本,可将 Excel 工作簿中的数据插入到 xml 文件中。 要编辑的 xml 文件是从 filedialogpicker 中选择的: 公共 strFile 作为字符串 子集路径() ' 声明...

回答 1 投票 0

如何迭代XSL并获取节点

我正在就我在尝试迭代和 XSLT 转换时面临的挑战问题与您联系。我有以下 XML 结构,我正在尝试获取值 AUFNR、BDMNG、

回答 1 投票 0

我正在尝试转换数据帧列表列表中的数据帧

我的数据如下:txt格式 时间 ;来源 ;行动 年-月-日;卡生物学;阅读成功 年-月-日;学生1;初始化的 年-月-日;书 1 ;首先退房 年-月-日;...

回答 1 投票 0

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