简体   繁体   English

如何使用Java在具有相同元素名称的xml中读写

[英]how to read and write in a xml having same element name using java

I have a xml with different number of elements like this. 我有一个具有不同数量元素的xml,像这样。

<name>
  <element></element>
  <element></element>
</name>
<name>
  <element></element>
  <element></element>
  <element></element>
</name>

I need to access the elements in java code. 我需要访问Java代码中的元素。

you can use jaxb library from the standard jdk, thus you do not need to add other dependency to your project. 您可以使用标准jdk中的jaxb库,因此无需在项目中添加其他依赖项。 Here is a good tutorial provided by Oracle: https://docs.oracle.com/javase/tutorial/jaxb/intro/ 这是Oracle提供的一个很好的教程: https : //docs.oracle.com/javase/tutorial/jaxb/intro/

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

相关问题 使用JAVA中的JDOM将多个同名元素写入xml文件 - Write more than one element with same name to xml file using JDOM in JAVA 如何删除具有相同名称的 XML 孩子 - How to remove XML child having same name 序列化和反序列化具有相同名称的 Jackson XML 元素 - Serialize and deserialize Jackson XML element having the same name 通过Java读取XML,替换文本和写入相同的XML文件 - Read XML, Replace Text and Write to same XML file via Java 如何使用JDOM以相同的名称编写和获取具有相同名称的所有xml元素 - how to write and get all the xml elements in same level with same name using JDOM 在 Java 中,如何将 JSON 或 XML 字符串映射到同一个 POJO,但 XML 具有与 JSON 不同的字段/属性名称? - In Java, how can I map a string that is either JSON or XML to the same POJO, but with the XML having one different field/attribute name from the JSON? 如何以Java编程方式读取XML元素? - How to read an XML element programmatically in Java? 如何在 Java 中使用 saxparser 读取嵌套的 xml 元素 - How to read nested xml element with saxparser in Java 如何使用具有不同根和子元素的jaxb将xml字符串转换为java对象列表 - How to convert xml string to list of java objects using jaxb having different root and child element 如何解析具有两个名称相同的标签的Xml - How to parse an Xml having two tags with same name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM