Tag: xml parsing

Java Regex还是XML解析器?

我想删除任何标签,如 hello hello 成为 hello hello 如果由于某种原因它正在使用正则表达式,那么最好的方法是什么?现在有人可以帮忙吗? (<|</)[:]{1,2}[^]> 编辑:添加

元素节点和文本节点之间的区别

John Computer Technology 6 E Foo Industrial Electronics 6 E 在简单的XML语言中, data 是一个元素。 根据我上面的XML, … 是一个元素,其他标签也是如此。 在DOM解析中,有一个Element节点和一个Text节点。 参考我正在使用的书, 是一个Element节点, , ,其他嵌套标签是Text节点。 那么,如果我正确理解DOM,所有外部标签都是Elements ,包含实际数据的标签是Text节点?

weblogic.xml中的错误:cvc-complex-type.2.4.a:找到以元素’prefer-application-packages’开头的无效内容

我正在使用spring source工具套件。 我在weblogic.xml文件中收到错误 – cvc-complex-type.2.4.a: Invalid content was found starting with element ‘prefer- application-packages’. One of ‘{“http://www.bea.com/ns/weblogic/weblogic-web-app”:retain- original-url, “http://www.bea.com/ns/weblogic/weblogic-web-app”:show-archived-real-path- enabled, “http://www.bea.com/ns/weblogic/weblogic-web-app”:require-admin-traffic, “http://www.bea.com/ns/weblogic/weblogic-web-app”:access-logging-disabled}’ is expected. enter code here 我的weblogic.xml看起来像这样 true 60 true true true antlr.* javax.persistence.* org.apache.commons.* true 错误显示在标签的开头..

如何在java中将xml标记存储为数组

在我的应用程序中,我正在解析一个xml文件。 在xml文件中,我有50个相同名称的标签question ,现在我想将所有名为question的标签存储为数组…. 在保存的标签中,我只想在文本视图中放置一个问号标签…. 如何执行此….请帮助我…..

@XmlElement有多个名字

我有一个情况,试图充当两个API之间的网关。 我需要做的是: 向APIa提出要求; 将XML响应解析(编组)到java对象中; 对它做一些改变; 然后以XML(unmarshal)向另一端(APIb)发出响应。 问题是我使用相同的对象来解析API响应并将响应发送到另一端。 public class ResponseAPI{ @XmlElement(name=”ResponseCode”) //I receive but I need to send private String responseCode; //getter and setter } 正如评论所说:我收到但我需要发送 有没有办法在不必创建另一个携带ResultCode的额外类的情况下完成这项工作? 提前致谢!

如何从一个XML JAVA中获取CDATA标记中包含的文本内容

我有以下XML: application/xml local-C++ 200 <![CDATA[]]> 我想从内容节点解析以下文本,如下所示: <![CDATA[]]> 请注意,内容包含在CDATA标记中。 如何使用任何方法在Java中完成此操作。 这是我的代码: @Test public void testGetDoOrchResponse() throws IOException { String path = “/Users/haddad/Git/Tools/ContentUtils/src/test/resources/testdata/doOrch_testfiles/doOrch_response.xml”; File f = new File(path); String response = FileUtils.readFileToString(f); String content = getDoOrchResponse(response, “content”); System.out.println(“Content: “+content); } //输出:内容:空白 static String getDoOrchResponse(String xml, String tagFragment) throws FileNotFoundException { String content = new String(); try { […]

在Saxon 9中他使用Java XML解析器,无法识别正则表达式中的单词边界(\ b)

我有以下简单的正则表达式: \b\w+\b Saxon报告以下错误: syntax error at char 2 in regular expression: Escape character ‘b’ not allowed 这是否意味着我不能在Java Saxon解析器中使用单词边界? 是否有另一种具有此function的免费XML Java解析器?

将xml作为字符串而不是使用xstream的类

我有类似的xml 15 我不需要在父对象中创建消息对象,而是将消息表示为String。 所以,当我做parent.message时,输出是 15 而不是消息对象。

XMl解析中的空指针exception

我需要解析一个Xml文档并将值存储在文本文件中,当我解析普通数据时(如果所有标签都有数据)然后它工作正常,但如果任何标签没有数据那么它抛出“Null pointerException”我需要什么为了避免空指针exception,请建议我使用示例代码示例xml: John Kaith Jho Sales Manager Sharon Eunis Shiny mack SAP Consulting 码: import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.w3c.dom.Node; import org.w3c.dom.Element; import java.io.File; public class ReadXMLFile { public static void main(String argv[]) { try { File fXmlFile = new File(“c:\\file.xml”); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc […]

Java,XML DocumentBuilder – 在解析时设置编码

我正在尝试保存一个树(扩展JTree ),它将XML文档保存到DOM Object并改变了它的结构。 我创建了一个新的文档对象,遍历了树以成功检索内容(包括XML文档的原始编码),现在有一个ByteArrayInputStream ,它具有正确编码的树内容( XML文档)。 问题是,当我解析ByteArrayInputStream ,编码会自动更改为UTF-8 (在XML文档中)。 有没有办法防止这种情况并使用ByteArrayInputStream提供的正确编码。 值得补充的是,我已经使用了 transformer.setOutputProperty(OutputKeys.ENCODING, encoding)方法检索正确的编码。 任何帮助,将不胜感激。