-
【问题来源】黑龙江农信社【问题简要】开发 vxml 版本自助语音流程时,使用grammer 标签 的 src 属性上送语法文件是,流程跟踪日志中,提示异常【问题类别】vxml 版本自主语音流程开发【AICC解决方案版本】AICC 版本:AICC 22.200.0【问题现象描述】页面中通过 grammar 标签 读取项目中一个 grammar.xml 文件流程文件中提示异常 There was a DEFINE_GRAMMAR failure 语法文件内容如下
-
dom4j是一个用于处理XML的开源框架,该框架集成了XPath,完全支持DOM,SAX,JAXP。本文主要介绍使用dom4j来处理XML,文中所使用到的软件版本:Java 1.8.0_191、dom4j 2.1.3、jaxen 1.2.0。1、前言 dom4j是一个十分优秀的JavaXML API,具有性能优异、功能强大和极其易使用的特点。DOM4J性能很好,连Sun的JAXM也在用DOM4J。目前许多开源项目中大量采用DOM4J,例如Hibernate使用DOM4J来读取XML配置文件。2、使用dom4j操作XML2.1、XML文件<?xml version="1.0" encoding="utf-8" ?> <school:grade xmlns:school="http://www.w3.org/TR/html4/school/"> <school:student rollno="1" school:age="10"> <school:firstname>cxx1</school:firstname> <lastname>Bob1</lastname> <nickname>stars1</nickname> <marks>85</marks> </school:student> <student rollno="2"> <firstname>cxx2</firstname> <lastname>Bob2</lastname> <nickname>stars2</nickname> <marks>85</marks> </student> <student rollno="3"> <firstname>cxx3</firstname> <lastname>Bob3</lastname> <nickname>stars3</nickname> <marks>85</marks> </student> </school:grade>2.2、pom.xml<dependency> <groupId>org.dom4j</groupId> <artifactId>dom4j</artifactId> <version>2.1.3</version> </dependency> <dependency> <groupId>jaxen</groupId> <artifactId>jaxen</artifactId> <version>1.2.0</version> </dependency> <build> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*</include> </includes> </resource> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> </resources> </build>2.3、Java代码例子该例子演示了使用dom4j解析XML、dom4j中XPath的使用以及使用dom4j来生成XML。package com.abc.demo.general.xml; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.Node; import org.dom4j.io.OutputFormat; import org.dom4j.io.SAXReader; import org.dom4j.io.XMLWriter; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.ByteArrayOutputStream; import java.util.List; /** * 使用dom4j处理xml */ public class Dom4jCase { private static Logger logger = LoggerFactory.getLogger(Dom4jCase.class); /** * 解析xml * @throws Exception */ @Test public void parse() throws Exception { SAXReader reader = new SAXReader(); Document document = reader.read(Dom4jCase.class.getResourceAsStream("student.xml"));//student.xml和Dom4jCase.java位于同一目录 //Document document = DocumentHelper.parseText(xmlString);//解析字符串 Element root = document.getRootElement(); List<Element> list = root.elements("student"); for (int i = 0; i < list.size(); i++) { Element student = list.get(i); logger.info("学生编号{}", student.attributeValue("rollno")); logger.info("age:{}", student.attributeValue("age")); logger.info("firstname:{}", student.elementText("firstname")); logger.info("lastname:{}", student.elementText("lastname")); logger.info("nickname:{}", student.elementText("nickname")); logger.info("marks:{}", student.elementText("marks")); } } /** * xpath使用 * @throws Exception */ @Test public void xpath() throws Exception { SAXReader reader = new SAXReader(); Document document = reader.read(Dom4jCase.class.getResourceAsStream("student.xml"));//student.xml和Dom4jCase.java位于同一目录 logger.info("查找存在rollno属性的student节点,找到的节点再查找lastname子节点,找到的节点再查找文本节点"); List<Node> list = document.selectNodes("//student[@rollno]/lastname/text()");//第二、三位学生 // List<Node> list = document.selectNodes("//student[@rollno]/child::lastname/text()");//效果同上 for (int i = 0; i < list.size(); i++) { Node node = list.get(i); logger.info(node.getText()); } logger.info("查找存在rollno属性的school:student节点"); list = document.selectNodes("//school:student[@rollno]");//第一位学生 for (int i = 0; i < list.size(); i++) { Node node = list.get(i); //获取rollno的属性值 logger.info(node.valueOf("@rollno")); } } /** * 生成xml */ @Test public void toXml() throws Exception { Document document = DocumentHelper.createDocument(); Element root = document.addElement("school:grade", "http://www.w3.org/TR/html4/school/"); //第一个学生 Element student = root.addElement("school:student"); student.addAttribute("rollno", "1"); student.addAttribute("school:age", "10"); student.addElement("school:firstname").setText("cxx1"); student.addElement("lastname").setText("Bob1"); student.addElement("nickname").setText("stars1"); student.addElement("marks").setText("85"); //第二个学生 student = root.addElement("student"); student.addAttribute("rollno", "2"); student.addElement("school:firstname").setText("cxx2"); student.addElement("lastname").setText("Bob2"); student.addElement("nickname").setText("stars2"); student.addElement("marks").setText("85"); //第三个学生 student = root.addElement("student"); student.addAttribute("rollno", "3"); student.addElement("school:firstname").setText("cxx3"); student.addElement("lastname").setText("Bob3"); student.addElement("nickname").setText("stars3"); student.addElement("marks").setText("85"); //直接转成字符串 // logger.info(document.asXML()); //格式化并输出到输出流 ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(out, format); writer.write(document); logger.info(out.toString()); } }转载自https://www.cnblogs.com/wuyongyin/p/14273893.html
-
JDOM是一个开源项目,它基于树型结构,利用纯JAVA的技术对XML文档实现解析、生成、序列化以及多种操作。本文主要介绍使用JDOM来处理XML,文中所使用到的软件版本:Java 1.8.0_191、JDOM 2.0.6。1、前言 W3C在设计DOM模型时,并不是针对某一种语言而设计,因此为了通用性,加入了许多繁琐而不必要的细节 ,使JAVA程序员在开发XML的应用程序过程中感到不甚方便,因此JDOM作为一种新型的XML解析器应运而生,它不遵循DOM模型,建立了自己独立的一套JDOM模型(注意JDOM决不是DOM扩展,虽然名字差不多,但两者是平行的关系),并提供功能强大使用方便的类库,使JAVA程序员可以更为高效的开发自己的XML应用程序,并极大的减少了代码量。2、使用JDOM操作XML2.1、XML文件<?xml version="1.0" encoding="utf-8" ?> <school:grade xmlns:school="http://www.w3.org/TR/html4/school/"> <school:student rollno="1" school:age="10"> <school:firstname>cxx1</school:firstname> <lastname>Bob1</lastname> <nickname>stars1</nickname> <marks>85</marks> </school:student> <student rollno="2"> <firstname>cxx2</firstname> <lastname>Bob2</lastname> <nickname>stars2</nickname> <marks>85</marks> </student> <student rollno="3"> <firstname>cxx3</firstname> <lastname>Bob3</lastname> <nickname>stars3</nickname> <marks>85</marks> </student> </school:grade>2.2、引入依赖<dependency> <groupId>org.jdom</groupId> <artifactId>jdom2</artifactId> <version>2.0.6</version> </dependency>2.3、Java代码例子该例子演示了使用JDOM解析XML、JDOM中XPath的使用以及使用JDOM来生成XML。package com.abc.demo.general.xml; import org.jdom2.*; import org.jdom2.filter.Filter; import org.jdom2.filter.Filters; import org.jdom2.input.SAXBuilder; import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; import org.jdom2.xpath.XPathBuilder; import org.jdom2.xpath.XPathExpression; import org.jdom2.xpath.XPathFactory; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.ByteArrayOutputStream; import java.util.List; /** * 使用JDOM处理xml */ public class JDomCase { private static Logger logger = LoggerFactory.getLogger(DomCase.class); /** * 解析xml * @throws Exception */ @Test public void parse() throws Exception { SAXBuilder sb = new SAXBuilder(); Document document = sb.build(DomCase.class.getResourceAsStream("student.xml")); Element root = document.getRootElement(); Namespace namespace = Namespace.getNamespace("school", "http://www.w3.org/TR/html4/school/"); List<Element> list = root.getChildren("student", namespace);//第1位学生 for (int i = 0; i < list.size(); i++) { Element student = list.get(i); logger.info("学生编号{}", student.getAttributeValue("rollno")); logger.info("age:{}", student.getAttributeValue("age", namespace)); logger.info("firstname:{}", student.getChildText("firstname", namespace)); logger.info("lastname:{}", student.getChildText("lastname")); logger.info("nickname:{}", student.getChildText("nickname")); logger.info("marks:{}", student.getChildText("marks")); } list = root.getChildren("student");//第2、3位学生 for (int i = 0; i < list.size(); i++) { Element student = list.get(i); logger.info("学生编号{}",student.getAttributeValue("rollno")); logger.info("firstname:{}", student.getChildText("firstname")); logger.info("lastname:{}", student.getChildText("lastname")); logger.info("nickname:{}", student.getChildText("nickname")); logger.info("marks:{}", student.getChildText("marks")); } } /** * xpath使用 * @throws Exception */ @Test public void xpath() throws Exception { SAXBuilder sb = new SAXBuilder(); Document document = sb.build(DomCase.class.getResourceAsStream("student.xml")); Namespace namespace = Namespace.getNamespace("school", "http://www.w3.org/TR/html4/school/"); Filter<Text> filter = Filters.text(); logger.info("查找所有的存在rollno属性的student节点,取出lastname的值"); XPathBuilder<Text> builder = new XPathBuilder<Text>("//student[@rollno]/lastname/text()", filter);//第2、3位学生 // XPathBuilder<Text> builder = new XPathBuilder<Text>("//student[@rollno]/child::lastname/text()", filter);//效果同上 // XPathBuilder<Text> builder = new XPathBuilder<Text>("//school:student[@rollno]/lastname/text()", filter);//第1位学生 builder.setNamespace(namespace); XPathExpression<Text> expression = builder.compileWith(XPathFactory.instance()); //XPathExpression<Object> expression = XPathFactory.instance().compile("//student[@rollno]/lastname/text()"); List<Text> list = expression.evaluate(document); for (int i = 0; i < list.size(); i++) { Text text = list.get(i); logger.info(text.getText()); } } /** * 生成xml */ @Test public void toXml() throws Exception { Document document = new Document(); Namespace namespace = Namespace.getNamespace("school", "http://www.w3.org/TR/html4/school/"); Element root = new Element("class", namespace); document.setRootElement(root); //第一个学生 Element student = new Element("student", namespace); student.setAttribute(new Attribute("rollno", "1")); student.setAttribute(new Attribute("age", "10", namespace)); Element firstname = new Element("firstname", namespace).setText("cxx1"); Element lastname = new Element("lastname").setText("Bob1"); Element nickname = new Element("nickname").setText("stars1"); Element marks = new Element("marks").setText("85"); student.addContent(firstname); student.addContent(lastname); student.addContent(nickname); student.addContent(marks); root.addContent(student); //第二个学生 student = new Element("student"); student.setAttribute(new Attribute("rollno", "2")); firstname = new Element("firstname", namespace).setText("cxx2"); lastname = new Element("lastname").setText("Bob2"); nickname = new Element("nickname").setText("stars2"); marks = new Element("marks").setText("85"); student.addContent(firstname); student.addContent(lastname); student.addContent(nickname); student.addContent(marks); root.addContent(student); //第三个学生 student = new Element("student"); student.setAttribute(new Attribute("rollno", "3")); firstname = new Element("firstname", namespace).setText("cxx3"); lastname = new Element("lastname").setText("Bob3"); nickname = new Element("nickname").setText("stars3"); marks = new Element("marks").setText("85"); student.addContent(firstname); student.addContent(lastname); student.addContent(nickname); student.addContent(marks); root.addContent(student); XMLOutputter xmlOutput = new XMLOutputter(); //xml格式化 Format format = Format.getRawFormat(); //文本缩进 format.setIndent(" "); format.setTextMode(Format.TextMode.TRIM_FULL_WHITE); xmlOutput.setFormat(format); ByteArrayOutputStream out = new ByteArrayOutputStream(); xmlOutput.output(document, out); logger.info(out.toString()); } }转载自https://www.cnblogs.com/wuyongyin/p/14273185.html
-
Woodstox是一个快速、开源的StAX实现;被视为执行效果最佳的StAX实现之一。本文主要介绍使用 Woodstox 来处理 XML,文中所使用到的软件版本:Java 1.8.0_191、woodstox-core-asl 4.4.1。1、引入依赖<dependency> <groupId>org.codehaus.woodstox</groupId> <artifactId>woodstox-core-asl</artifactId> <version>4.4.1</version> </dependency>2、Woodstox例子2.1、XML文件<?xml version="1.0" encoding="utf-8" ?> <school:grade xmlns:school="http://www.w3.org/TR/html4/school/"> <school:student rollno="1" school:age="10"> <school:firstname>cxx1</school:firstname> <lastname>Bob1</lastname> <nickname>stars1</nickname> <marks>85</marks> </school:student> <student rollno="2"> <firstname>cxx2</firstname> <lastname>Bob2</lastname> <nickname>stars2</nickname> <marks>85</marks> </student> <student rollno="3"> <firstname>cxx3</firstname> <lastname>Bob3</lastname> <nickname>stars3</nickname> <marks>85</marks> </student> </school:grade>2.2、Java代码例子该例子演示如何使用Woodstox来解析XML以及使用Woodstox来生成XML。package com.abc.demo.general.xml; import org.apache.commons.lang.StringUtils; import org.codehaus.stax2.*; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.xml.namespace.QName; import javax.xml.stream.*; import javax.xml.stream.events.Attribute; import javax.xml.stream.events.XMLEvent; import java.util.ArrayList; import java.util.List; /** * 使用Woodstox处理xml */ public class WoodstoxCase { private static Logger logger = LoggerFactory.getLogger(WoodstoxCase.class); /** * 基于光标的方式解析xml * @throws Exception */ @Test public void parse() throws Exception { XMLInputFactory2 factory = (XMLInputFactory2)XMLInputFactory2.newFactory(); XMLStreamReader2 reader = (XMLStreamReader2)factory.createXMLStreamReader(WoodstoxCase.class.getResourceAsStream("student.xml")); //添加过滤器 XMLStreamReader2 filterReader = (XMLStreamReader2)factory.createFilteredReader(reader, new StreamFilter() { @Override public boolean accept(XMLStreamReader reader) { if (reader.isStartElement() || reader.isEndElement() || reader.isCharacters()) { return true; } return false; } }); List<Student> students = new ArrayList<>(); Student student = null; String text = ""; while (filterReader.hasNext()) { int type = filterReader.next(); if (type == XMLStreamReader.START_ELEMENT) { if ("student".equals(reader.getName().getLocalPart())) { student = new Student(); students.add(student); student.setRollno(Integer.parseInt(reader.getAttributeValue("", "rollno"))); String age = reader.getAttributeValue("http://www.w3.org/TR/html4/school/", "age"); if (StringUtils.isNotBlank(age)) { student.setAge(Integer.parseInt(age)); } } } else if (type == XMLStreamReader.END_ELEMENT) { logger.info(reader.getName().getLocalPart()); if ("firstname".equals(reader.getName().getLocalPart())) { student.setFirstname(text); } else if ("lastname".equals(reader.getName().getLocalPart())) { student.setLastname(text); } else if ("nickname".equals(reader.getName().getLocalPart())) { student.setNickname(text); } else if ("marks".equals(reader.getName().getLocalPart())) { student.setMarks(text); } } else if (type == XMLStreamReader.CHARACTERS) { text = reader.getText(); } } logger.info(students.toString()); } /** * 基于迭代模型的方式解析xml * @throws Exception */ @Test public void parse2() throws Exception { XMLInputFactory2 factory = (XMLInputFactory2)XMLInputFactory.newInstance(); XMLEventReader2 reader = (XMLEventReader2)factory.createXMLEventReader(WoodstoxCase.class.getResourceAsStream("student.xml")); //添加过滤器 XMLEventReader2 filterReader = (XMLEventReader2)factory.createFilteredReader(reader, event -> { //处理开始节点 if (event.isStartElement() || event.isEndElement() || event.isCharacters()) { return true; } return false; }); List<Student> students = new ArrayList<>(); Student student = null; String text = ""; while (filterReader.hasNext()) { XMLEvent event = filterReader.nextEvent(); if (event.isStartElement()) { if ("student".equals(event.asStartElement().getName().getLocalPart())) { student = new Student(); students.add(student); student.setRollno(Integer.parseInt(event.asStartElement().getAttributeByName(new QName("", "rollno")).getValue())); Attribute ageAttribute = event.asStartElement().getAttributeByName(new QName("http://www.w3.org/TR/html4/school/", "age")); if (ageAttribute != null) { student.setAge(Integer.parseInt(ageAttribute.getValue())); } } } else if (event.isEndElement()) { logger.info(event.asEndElement().getName().getLocalPart()); if ("firstname".equals(event.asEndElement().getName().getLocalPart())) { student.setFirstname(text); } else if ("lastname".equals(event.asEndElement().getName().getLocalPart())) { student.setLastname(text); } else if ("nickname".equals(event.asEndElement().getName().getLocalPart())) { student.setNickname(text); } else if ("marks".equals(event.asEndElement().getName().getLocalPart())) { student.setMarks(text); } } else if (event.isCharacters()) { text = event.asCharacters().getData(); } } logger.info(students.toString()); } /** * 生成xml * @throws Exception */ @Test public void toXml() throws Exception { XMLOutputFactory2 factory = (XMLOutputFactory2)XMLOutputFactory2.newInstance(); XMLStreamWriter2 writer = (XMLStreamWriter2)factory.createXMLStreamWriter(System.out); writer.writeStartDocument("UTF-8", "1.0"); writer.writeStartElement("school", "class", "http://www.w3.org/TR/html4/school/"); //第一个学生 writer.writeStartElement("school", "student", "http://www.w3.org/TR/html4/school/"); writer.writeAttribute("rollno", "1"); writer.writeAttribute("school","http://www.w3.org/TR/html4/school/", "age", "10"); writer.writeStartElement("school", "firstname", "http://www.w3.org/TR/html4/school/"); writer.writeCharacters("cxx1"); writer.writeEndElement(); writer.writeStartElement("lastname"); writer.writeCharacters("Bob1"); writer.writeEndElement(); writer.writeStartElement("nickname"); writer.writeCharacters("stars1"); writer.writeEndElement(); writer.writeStartElement("marks"); writer.writeCharacters("85"); writer.writeEndElement(); writer.writeEndElement(); //第二个学生 writer.writeStartElement("student"); writer.writeAttribute("rollno", "2"); writer.writeStartElement("firstname"); writer.writeCharacters("cxx2"); writer.writeEndElement(); writer.writeStartElement("lastname"); writer.writeCharacters("Bob2"); writer.writeEndElement(); writer.writeStartElement("nickname"); writer.writeCharacters("stars2"); writer.writeEndElement(); writer.writeStartElement("marks"); writer.writeCharacters("85"); writer.writeEndElement(); writer.writeEndElement(); //第三个学生 writer.writeStartElement("student"); writer.writeAttribute("rollno", "3"); writer.writeStartElement("firstname"); writer.writeCharacters("cxx3"); writer.writeEndElement(); writer.writeStartElement("lastname"); writer.writeCharacters("Bob3"); writer.writeEndElement(); writer.writeStartElement("nickname"); writer.writeCharacters("stars3"); writer.writeEndElement(); writer.writeStartElement("marks"); writer.writeCharacters("85"); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndDocument(); } }Student实体类:package com.abc.demo.general.xml; /** * 学生 */ public class Student { private int rollno; private int age; private String firstname; private String lastname; private String nickname; private String marks; public Student() {} public Student(int rollno, int age, String firstname, String lastname, String nickname, String marks) { this.rollno = rollno; this.age = age; this.firstname = firstname; this.lastname = lastname; this.nickname = nickname; this.marks = marks; } public int getRollno() { return rollno; } public void setRollno(int rollno) { this.rollno = rollno; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } public String getLastname() { return lastname; } public void setLastname(String lastname) { this.lastname = lastname; } public String getNickname() { return nickname; } public void setNickname(String nickname) { this.nickname = nickname; } public String getMarks() { return marks; } public void setMarks(String marks) { this.marks = marks; } @Override public String toString() { return "Student{" + "rollno=" + rollno + ", age=" + age + ", firstname='" + firstname + '\'' + ", lastname='" + lastname + '\'' + ", nickname='" + nickname + '\'' + ", marks='" + marks + '\'' + '}'; } }转载自https://www.cnblogs.com/wuyongyin/p/14333642.html
-
StAX(Stream API for XML)是一种针对XML的流式拉分析API。本文主要介绍使用StAX方式处理XML,文中所使用到的软件版本:Java 1.8.0_191。1、StAX简介 StAX通过提供一种基于事件迭代器(Iterator)的API让使用者去控制xml文档解析过程,遍历这个事件迭代器去处理每一个解析事件,解析事件可以看做是程序拉出来的,也就是程序促使解析器产生一个解析事件然后处理该事件,之后又促使解析器产生下一个解析事件,如此循环直到碰到文档结束符。1.1、与SAX区别SAX和STAX都是基于事件驱动的。SAX是推模式----解析器控制xml文件解析,由解析器调用相应的事件方法。STAX是拉模式-----客户端程序自己控制xml事件,主动调用相应的事件方法。1.2、拉模式的优点1.在拉模式中,事件是由分析应用程序生成的,因此把分析规则提供到客户端而不是分析器。2.拉模式的代码更简单并且它比推模式使用更少的库。3.拉模式客户端能同时读多个XML文档。4.拉模式允许你过滤XML文档并且跳过分析事件。2、StAX使用2.1、XML文件<?xml version="1.0" encoding="utf-8" ?> <school:grade xmlns:school="http://www.w3.org/TR/html4/school/"> <school:student rollno="1" school:age="10"> <school:firstname>cxx1</school:firstname> <lastname>Bob1</lastname> <nickname>stars1</nickname> <marks>85</marks> </school:student> <student rollno="2"> <firstname>cxx2</firstname> <lastname>Bob2</lastname> <nickname>stars2</nickname> <marks>85</marks> </student> <student rollno="3"> <firstname>cxx3</firstname> <lastname>Bob3</lastname> <nickname>stars3</nickname> <marks>85</marks> </student> </school:grade>2.2、Java代码例子该例子演示如何使用StAX方式解析XML以及使用StAX方式来生成XML。package com.abc.demo.general.xml; import org.apache.commons.lang.StringUtils; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.xml.namespace.QName; import javax.xml.stream.*; import javax.xml.stream.events.Attribute; import javax.xml.stream.events.XMLEvent; import java.util.ArrayList; import java.util.List; public class StaxCase { private static Logger logger = LoggerFactory.getLogger(StaxCase.class); /** * 基于光标的方式解析xml * @throws Exception */ @Test public void parse() throws Exception { XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory.createXMLStreamReader(StaxCase.class.getResourceAsStream("student.xml")); //添加过滤器 XMLStreamReader filterReader = factory.createFilteredReader(reader, new StreamFilter() { @Override public boolean accept(XMLStreamReader reader) { //处理开始节点 if (reader.isStartElement() || reader.isEndElement() || reader.isCharacters()) { return true; } return false; } }); List<Student> students = new ArrayList<>(); Student student = null; String text = ""; while (filterReader.hasNext()) { int type = filterReader.next(); if (type == XMLStreamReader.START_ELEMENT) { if ("student".equals(reader.getName().getLocalPart())) { student = new Student(); students.add(student); student.setRollno(Integer.parseInt(reader.getAttributeValue("", "rollno"))); String age = reader.getAttributeValue("http://www.w3.org/TR/html4/school/", "age"); if (StringUtils.isNotBlank(age)) { student.setAge(Integer.parseInt(age)); } } } else if (type == XMLStreamReader.END_ELEMENT) { logger.info(reader.getName().getLocalPart()); if ("firstname".equals(reader.getName().getLocalPart())) { student.setFirstname(text); } else if ("lastname".equals(reader.getName().getLocalPart())) { student.setLastname(text); } else if ("nickname".equals(reader.getName().getLocalPart())) { student.setNickname(text); } else if ("marks".equals(reader.getName().getLocalPart())) { student.setMarks(text); } } else if (type == XMLStreamReader.CHARACTERS) { text = reader.getText(); } } logger.info(students.toString()); } /** * 基于迭代模型的方式解析xml * @throws Exception */ @Test public void parse2() throws Exception { XMLInputFactory factory = XMLInputFactory.newInstance(); XMLEventReader reader = factory.createXMLEventReader(StaxCase.class.getResourceAsStream("student.xml")); //添加过滤器 XMLEventReader filterReader = factory.createFilteredReader(reader, event -> { //处理开始节点 if (event.isStartElement() || event.isEndElement() || event.isCharacters()) { return true; } return false; }); List<Student> students = new ArrayList<>(); Student student = null; String text = ""; while (filterReader.hasNext()) { XMLEvent event = filterReader.nextEvent(); if (event.isStartElement()) { if ("student".equals(event.asStartElement().getName().getLocalPart())) { student = new Student(); students.add(student); student.setRollno(Integer.parseInt(event.asStartElement().getAttributeByName(new QName("", "rollno")).getValue())); Attribute ageAttribute = event.asStartElement().getAttributeByName(new QName("http://www.w3.org/TR/html4/school/", "age")); if (ageAttribute != null) { student.setAge(Integer.parseInt(ageAttribute.getValue())); } } } else if (event.isEndElement()) { logger.info(event.asEndElement().getName().getLocalPart()); if ("firstname".equals(event.asEndElement().getName().getLocalPart())) { student.setFirstname(text); } else if ("lastname".equals(event.asEndElement().getName().getLocalPart())) { student.setLastname(text); } else if ("nickname".equals(event.asEndElement().getName().getLocalPart())) { student.setNickname(text); } else if ("marks".equals(event.asEndElement().getName().getLocalPart())) { student.setMarks(text); } } else if (event.isCharacters()) { text = event.asCharacters().getData(); } } logger.info(students.toString()); } /** * 生成xml * @throws Exception */ @Test public void toXml() throws Exception { XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = factory.createXMLStreamWriter(System.out); writer.writeStartDocument("UTF-8", "1.0"); writer.writeStartElement("school", "class", "http://www.w3.org/TR/html4/school/"); //第一个学生 writer.writeStartElement("school", "student", "http://www.w3.org/TR/html4/school/"); writer.writeAttribute("rollno", "1"); writer.writeAttribute("school","http://www.w3.org/TR/html4/school/", "age", "10"); writer.writeStartElement("school", "firstname", "http://www.w3.org/TR/html4/school/"); writer.writeCharacters("cxx1"); writer.writeEndElement(); writer.writeStartElement("lastname"); writer.writeCharacters("Bob1"); writer.writeEndElement(); writer.writeStartElement("nickname"); writer.writeCharacters("stars1"); writer.writeEndElement(); writer.writeStartElement("marks"); writer.writeCharacters("85"); writer.writeEndElement(); writer.writeEndElement(); //第二个学生 writer.writeStartElement("student"); writer.writeAttribute("rollno", "2"); writer.writeStartElement("firstname"); writer.writeCharacters("cxx2"); writer.writeEndElement(); writer.writeStartElement("lastname"); writer.writeCharacters("Bob2"); writer.writeEndElement(); writer.writeStartElement("nickname"); writer.writeCharacters("stars2"); writer.writeEndElement(); writer.writeStartElement("marks"); writer.writeCharacters("85"); writer.writeEndElement(); writer.writeEndElement(); //第三个学生 writer.writeStartElement("student"); writer.writeAttribute("rollno", "3"); writer.writeStartElement("firstname"); writer.writeCharacters("cxx3"); writer.writeEndElement(); writer.writeStartElement("lastname"); writer.writeCharacters("Bob3"); writer.writeEndElement(); writer.writeStartElement("nickname"); writer.writeCharacters("stars3"); writer.writeEndElement(); writer.writeStartElement("marks"); writer.writeCharacters("85"); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndDocument(); } }Student实体类:package com.abc.demo.general.xml; /** * 学生 */ public class Student { private int rollno; private int age; private String firstname; private String lastname; private String nickname; private String marks; public Student() {} public Student(int rollno, int age, String firstname, String lastname, String nickname, String marks) { this.rollno = rollno; this.age = age; this.firstname = firstname; this.lastname = lastname; this.nickname = nickname; this.marks = marks; } public int getRollno() { return rollno; } public void setRollno(int rollno) { this.rollno = rollno; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } public String getLastname() { return lastname; } public void setLastname(String lastname) { this.lastname = lastname; } public String getNickname() { return nickname; } public void setNickname(String nickname) { this.nickname = nickname; } public String getMarks() { return marks; } public void setMarks(String marks) { this.marks = marks; } @Override public String toString() { return "Student{" + "rollno=" + rollno + ", age=" + age + ", firstname='" + firstname + '\'' + ", lastname='" + lastname + '\'' + ", nickname='" + nickname + '\'' + ", marks='" + marks + '\'' + '}'; } }转载自https://www.cnblogs.com/wuyongyin/p/14327032.html
-
SAX 是一个用于处理XML事件驱动的“推”模型,虽然它不是W3C标准,但它却是一个得到了广泛认可的API。本文主要介绍 Java SAX 方式处理 XML,文中所使用到的软件版本:Java 1.8.0_191。1、SAX 简介 SAX 的全称是 Simple APIs for XML,也即 XML 简单应用程序接口。与DOM不同,SAX 提供的访问模式是一种顺序模式,这是一种快速读写 XML 数据的方式。当使用 SAX 分析器对 XML 文档进行分析时,会触发一系列事件,并激活相应的事件处理函数,应用程序通过这些事件处理函数实现对XML文档的访问,因而 SAX 接口也被称作事件驱动接口。1.1、SAX 的优点1、顺序读入文档并产生相应事件,可以处理任何大小的XML文档。2、适用于只需要文档的部分内容,或者只需要从文档中得到特定信息。1.2、SAX 的缺点1、只能对文档按顺序解析一遍,不支持对文档的随意访问。2、只能读取XML文档内容,而不能修改。3、开发上比较复杂,需要自己来实现事件处理器。2、Java SAX 方式操作 XML2.1、XML 文件<?xml version="1.0" encoding="utf-8" ?> <school:grade xmlns:school="http://www.w3.org/TR/html4/school/"> <school:student rollno="1" school:age="10"> <school:firstname>cxx1</school:firstname> <lastname>Bob1</lastname> <nickname>stars1</nickname> <marks>85</marks> </school:student> <student rollno="2"> <firstname>cxx2</firstname> <lastname>Bob2</lastname> <nickname>stars2</nickname> <marks>85</marks> </student> <student rollno="3"> <firstname>cxx3</firstname> <lastname>Bob3</lastname> <nickname>stars3</nickname> <marks>85</marks> </student> </school:grade>2.2、Java 代码例子该例子演示如何使用 SAX 方式解析 XML 以及使用 SAX 方式来生成 XML。package com.abc.demo.general.xml; import org.apache.commons.lang.StringUtils; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.DefaultHandler; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamResult; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.List; public class SaxCase { private static Logger logger = LoggerFactory.getLogger(SaxCase.class); /** * 解析xml * @throws Exception */ @Test public void parse() throws Exception { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); SaxHandler handler = new SaxHandler(); parser.parse(DomCase.class.getResourceAsStream("student.xml"), handler); logger.info(handler.getStudents().toString()); } /** * 生成xml * @throws Exception */ @Test public void toXml() throws Exception { //创建SAX转换工厂 SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler handler = factory.newTransformerHandler(); //创建handler转换器 Transformer transformer = handler.getTransformer(); //换行 transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); ByteArrayOutputStream out = new ByteArrayOutputStream(); StreamResult streamResult = new StreamResult(out); handler.setResult(streamResult); AttributesImpl attributes = new AttributesImpl(); //打开doc对象 handler.startDocument(); handler.startElement("http://www.w3.org/TR/html4/school/", "", "school:class", null); //第一个学生 attributes.clear(); attributes.addAttribute("", "", "rollno", "", "1"); attributes.addAttribute("", "", "school:age", "", "10"); handler.startElement("", "", "student", attributes); handler.startElement("", "", "school:firstname", null); handler.characters("cxx1".toCharArray(), 0, 4); handler.endElement("", "", "school:firstname"); handler.startElement("", "", "lastname", null); handler.characters("Bob1".toCharArray(), 0, 4); handler.endElement("", "", "lastname"); handler.startElement("", "", "nickname", null); handler.characters("stars1".toCharArray(), 0, 6); handler.endElement("", "", "nickname"); handler.startElement("", "", "marks", null); handler.characters("85".toCharArray(), 0, 2); handler.endElement("", "", "marks"); handler.endElement("", "", "student"); //第二个学生 attributes.clear(); attributes.addAttribute("", "", "rollno", "", "2"); handler.startElement("", "", "student", attributes); handler.startElement("", "", "firstname", null); handler.characters("cxx2".toCharArray(), 0, 4); handler.endElement("", "", "firstname"); handler.startElement("", "", "lastname", null); handler.characters("Bob2".toCharArray(), 0, 4); handler.endElement("", "", "lastname"); handler.startElement("", "", "nickname", null); handler.characters("stars2".toCharArray(), 0, 6); handler.endElement("", "", "nickname"); handler.startElement("", "", "marks", null); handler.characters("85".toCharArray(), 0, 2); handler.endElement("", "", "marks"); handler.endElement("", "", "student"); //第三个学生 attributes.clear(); attributes.addAttribute("", "", "rollno", "", "3"); handler.startElement("", "", "student", attributes); handler.startElement("", "", "firstname", null); handler.characters("cxx3".toCharArray(), 0, 4); handler.endElement("", "", "firstname"); handler.startElement("", "", "lastname", null); handler.characters("Bob3".toCharArray(), 0, 4); handler.endElement("", "", "lastname"); handler.startElement("", "", "nickname", null); handler.characters("stars3".toCharArray(), 0, 6); handler.endElement("", "", "nickname"); handler.startElement("", "", "marks", null); handler.characters("85".toCharArray(), 0, 2); handler.endElement("", "", "marks"); handler.endElement("", "", "student"); handler.endElement("", "", "school:class"); handler.endDocument(); logger.info(out.toString()); } } class SaxHandler extends DefaultHandler { private String text; private static Logger logger = LoggerFactory.getLogger(SaxHandler.class); private List<Student> students = new ArrayList<>(); private Student student = null; public List<Student> getStudents() { return students; } public SaxHandler() {} @Override public void startDocument() throws SAXException { super.startDocument(); logger.info("SAX解析开始"); } @Override public void endDocument() throws SAXException { super.endDocument(); logger.info("SAX解析结束"); } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { super.startElement(uri, localName, qName, attributes); logger.info("qName={}", qName); if (qName.equals("student") || qName.equals("school:student")) { student = new Student(); students.add(student); student.setRollno(Integer.parseInt(attributes.getValue("rollno"))); String age = attributes.getValue("school:age"); if (StringUtils.isNotBlank(age)) { student.setAge(Integer.parseInt(age)); } } } @Override public void endElement(String uri, String localName, String qName) throws SAXException { super.endElement(uri, localName, qName); if ("firstname".equals(qName) || "school:firstname".equals(qName) ) { student.setFirstname(text); } else if ("lastname".equals(qName)) { student.setLastname(text); } else if ("nickname".equals(qName)) { student.setNickname(text); } else if ("marks".equals(qName)) { student.setMarks(text); } } @Override public void characters(char[] ch, int start, int length) throws SAXException { super.characters(ch, start, length); text = new String(ch, start, length); } } Student 实体类:package com.abc.demo.general.xml; /** * 学生 */ public class Student { private int rollno; private int age; private String firstname; private String lastname; private String nickname; private String marks; public Student() {} public Student(int rollno, int age, String firstname, String lastname, String nickname, String marks) { this.rollno = rollno; this.age = age; this.firstname = firstname; this.lastname = lastname; this.nickname = nickname; this.marks = marks; } public int getRollno() { return rollno; } public void setRollno(int rollno) { this.rollno = rollno; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } public String getLastname() { return lastname; } public void setLastname(String lastname) { this.lastname = lastname; } public String getNickname() { return nickname; } public void setNickname(String nickname) { this.nickname = nickname; } public String getMarks() { return marks; } public void setMarks(String marks) { this.marks = marks; } @Override public String toString() { return "Student{" + "rollno=" + rollno + ", age=" + age + ", firstname='" + firstname + '\'' + ", lastname='" + lastname + '\'' + ", nickname='" + nickname + '\'' + ", marks='" + marks + '\'' + '}'; } }转载自https://www.cnblogs.com/wuyongyin/p/14268108.html
-
XML DOM 定义了访问和处理 XML 文档的标准方法,DOM 是 W3C(万维网联盟)的推荐标准。本文主要介绍 Java DOM 方式处理 XML,文中所使用到的软件版本:Java 1.8.0_191、jaxen 1.2.0。1、DOM简介 DOM 的全称是 Document Object Model,也即文档对象模型。在应用程序中,基于 DOM 的 XML 分析器将一个 XML 文档转换成一个对象模型的集合(通常称 DOM 树),应用程序正是通过对这个对象模型的操作,来实现对XML文档数据的操作。通过 DOM 接口,应用程序可以在任何时候访问 XML 文档中的任何一部分数据,因此,这种利用DOM接口的机制也被称作随机访问机制。 DOM 接口提供了一种通过分层对象模型来访问 XML 文档信息的方式,这些分层对象模型依据 XML 的文档结构形成了一棵节点树。无论 XML 文档中所描述的是什么类型的信息,即便是制表数据、项目列表或一个文档,利用DOM所生成的模型都是节点树的形式。也就是说,DOM 强制使用树模型来访问XML文档中的信息。由于 XML 本质上就是一种分层结构,所以这种描述方法是相当有效的。 DOM 树所提供的随机访问方式给应用程序的开发带来了很大的灵活性,它可以任意地控制整个XML文档中的内容。然而,由于 DOM 分析器把整个XML文档转化成DOM树放在了内存中,因此,当文档比较大或者结构比较复杂时,对内存的需求就比较高。而且,对于结构复杂的树的遍历也是一项耗时的操作。所以,DOM 分析器对机器性能的要求比较高,实现效率不十分理想。不过,由于 DOM 分析器所采用的树结构的思想与XML文档的结构相吻合,同时鉴于随机访问所带来的方便,因此,DOM 分析器还是有很广泛的使用价值的。1.1、DOM 的优点1、可以随意访问文档树的任何部分,没有次数限制。2、可以随意修改文档树,从而修改XML文档。3、易于理解,易于开发。1.2、DOM 的缺点1、在内存中创建文档树,不适于处理大型XML文档。2、Java DOM方式操作XML2.1、XML 文件<?xml version="1.0" encoding="utf-8" ?> <school:grade xmlns:school="http://www.w3.org/TR/html4/school/"> <school:student rollno="1" school:age="10"> <school:firstname>cxx1</school:firstname> <lastname>Bob1</lastname> <nickname>stars1</nickname> <marks>85</marks> </school:student> <student rollno="2"> <firstname>cxx2</firstname> <lastname>Bob2</lastname> <nickname>stars2</nickname> <marks>85</marks> </student> <student rollno="3"> <firstname>cxx3</firstname> <lastname>Bob3</lastname> <nickname>stars3</nickname> <marks>85</marks> </student> </school:grade>2.2、Java 代码例子该例子演示了使用DOM方式解析XML、DOM方式下XPath的使用以及使用DOM方式来生成XML。package com.abc.demo.general.xml; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import javax.xml.namespace.NamespaceContext; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathFactory; import java.io.ByteArrayOutputStream; import java.util.Iterator; /** * dom方式处理xml */ public class DomCase { private static Logger logger = LoggerFactory.getLogger(DomCase.class); /** * 解析xml * @throws Exception */ @Test public void parse() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); //支持命名空间 factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); //解析xml文件为文档 Document document = builder.parse(DomCase.class.getResourceAsStream("student.xml")); Element rootElement = document.getDocumentElement(); NodeList list = rootElement.getChildNodes();//所有学生 // NodeList list = document.getElementsByTagName("school:student"); //第1个学生 // NodeList list = document.getElementsByTagName("student"); //第2、3的学生 // NodeList list = document.getElementsByTagNameNS("http://www.w3.org/TR/html4/school/", "student");//第1个学生 for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) { continue; } logger.info("学生编号" + node.getAttributes().getNamedItem("rollno").getTextContent()); if (node.getAttributes().getNamedItem("school:age") != null) { logger.info("age=" + node.getAttributes().getNamedItem("school:age").getTextContent()); } NodeList childNodes = node.getChildNodes(); for (int j = 0; j < childNodes.getLength() ; j++) { Node childNode = childNodes.item(j); if (childNode.getNodeType() == Node.ELEMENT_NODE) { logger.info(childNode.getNodeName() + ":" + childNode.getFirstChild().getNodeValue()); } } } } /** * xpath使用 * @throws Exception */ @Test public void xpath() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); //支持命名空间 factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); //解析xml文件为文档 Document document = builder.parse(DomCase.class.getResourceAsStream("student.xml")); XPathFactory xPathFactory = XPathFactory.newInstance(); XPath xpath = xPathFactory.newXPath(); xpath.setNamespaceContext(new NamespaceContext() { @Override public String getNamespaceURI(String prefix) { if ("school".equals(prefix)) { return "http://www.w3.org/TR/html4/school/"; } return null; } @Override public String getPrefix(String namespaceURI) { return null; } @Override public Iterator getPrefixes(String namespaceURI) { return null; } }); logger.info("查找所有的存在rollno属性的student节点,取出lastname的值"); XPathExpression expr = xpath.compile("//student[@rollno]/lastname/text()");//第2、3位学生 // XPathExpression expr = xpath.compile("//student[@rollno]/child::lastname/text()");//效果同上 // XPathExpression expr = xpath.compile("//school:student[@rollno]/lastname/text()");//第1位学生 Object result = expr.evaluate(document, XPathConstants.NODESET); NodeList nodes = (NodeList) result; for (int i = 0; i < nodes.getLength(); i++) { logger.info(nodes.item(i).getNodeValue()); } } /** * 生成xml */ @Test public void toXml() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); //新建一个文档对象 Document document = builder.newDocument(); Element elementClass = document.createElementNS("http://www.w3.org/TR/html4/school/", "school:class"); //第一个学生 Element elementStudent1 = document.createElement("student"); elementStudent1.setAttribute("rollno", "1"); elementStudent1.setAttributeNS("http://www.w3.org/TR/html4/school/", "school:age", "10"); Element elementFirstname1 = document.createElement("school:firstname"); elementFirstname1.setTextContent("cxx1"); Element elementLastname1 = document.createElement("lastname"); elementLastname1.setTextContent("Bob1"); Element elementNickname1 = document.createElement("nickname"); elementNickname1.setTextContent("stars1"); Element elementMarks1 = document.createElement("marks"); elementMarks1.setTextContent("85"); elementStudent1.appendChild(elementFirstname1); elementStudent1.appendChild(elementLastname1); elementStudent1.appendChild(elementNickname1); elementStudent1.appendChild(elementMarks1); elementClass.appendChild(elementStudent1); //第二个学生 Element elementStudent2 = document.createElement("student"); elementStudent2.setAttribute("rollno", "2"); Element elementFirstname2 = document.createElement("firstname"); elementFirstname2.setTextContent("cxx2"); Element elementLastname2 = document.createElement("lastname"); elementLastname2.setTextContent("Bob2"); Element elementNickname2 = document.createElement("nickname"); elementNickname2.setTextContent("stars2"); Element elementMarks2 = document.createElement("marks"); elementMarks2.setTextContent("85"); elementStudent2.appendChild(elementFirstname2); elementStudent2.appendChild(elementLastname2); elementStudent2.appendChild(elementNickname2); elementStudent2.appendChild(elementMarks2); elementClass.appendChild(elementStudent2); //第三个学生 Element elementStudent3 = document.createElement("student"); elementStudent3.setAttribute("rollno", "3"); Element elementFirstname3 = document.createElement("firstname"); elementFirstname3.setTextContent("cxx3"); Element elementLastname3 = document.createElement("lastname"); elementLastname3.setTextContent("Bob3"); Element elementNickname3 = document.createElement("nickname"); elementNickname3.setTextContent("stars3"); Element elementMarks3 = document.createElement("marks"); elementMarks3.setTextContent("85"); elementStudent3.appendChild(elementFirstname3); elementStudent3.appendChild(elementLastname3); elementStudent3.appendChild(elementNickname3); elementStudent3.appendChild(elementMarks3); elementClass.appendChild(elementStudent3); document.appendChild(elementClass); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING,"utf-8"); //换行 transformer.setOutputProperty(OutputKeys.INDENT, "yes"); DOMSource domSource = new DOMSource(document); //xml输出到的地方 ByteArrayOutputStream out = new ByteArrayOutputStream(); StreamResult streamResult = new StreamResult(out); transformer.transform(domSource, streamResult); logger.info(out.toString()); } }转载自https://www.cnblogs.com/wuyongyin/p/14266756.html
-
【问题来源】广发银行 【问题简要】vxml如果实现呼叫早释放后进行虚拟排队【问题类别】IVR(vxml1.0 )【AICC解决方案版本】 【AICC版本:AICC 8.15.0 (计划升级到22.200版本) 【CTI版本:3.8c23SBC006】【期望解决时间】2022.4.24【问题现象描述】 需求是要支持以下场景:客户拨打电话进入排队,在排队过程中释放该呼叫,系统自动生产虚拟呼叫继续在当前位置排队,当有空虚座席服务该虚拟呼叫时,系统自动外呼该客户的电话,并将该呼叫转给座席处理。请问使用vxml如何实现虚拟排队?
-
【问题来源】广发银行 【问题简要】如何实现IVR全流程录音【问题类别】IVR(vxml1.0 )【AICC解决方案版本】 【AICC版本:AICC 8.15.0, 【CTI版本:3.8c23SBC006】【期望解决时间】2022.4.5【问题现象描述】这边客户的需求是需要支持IVR全流程录音(即从进入ivr播报欢迎语开始至退出IVR的整个流程的IVR语音都要录制下来),请问这个要如何实现?
-
【问题来源】【必填】 增城税局【问题简要】【必填】VXML脚本基础cell,请求接口报错,找不到问题原因【问题类别】【必填】 ivr流程开发【AICC解决方案版本】【必填】ICD V300R006C90U3SpC702【期望解决时间】【选填】3月8日内解决【问题现象描述】【必填】已知问题:1、接口那边没有接收到请求;2、在远程环境中使用postman请求接口能正常返回;3、在IVR机器上使用telnet命令,检测短信接口地址网络是能通的。 以下是cell配置和报错日志图,附vxml<vxml version="1.0"> <form> <var name="httpHead" expr="session.sce.httpHead"/> <script> var httpStr = httpHead; </script> <subdialog name="goodsInfor" namelist="session.sce.phones session.sce.contentKey session.sce.orgi" srcexpr="httpStr" > <filled> <assign name="session.sce.result" expr="goodsInfor.result"/> </filled> </subdialog> </form> </vxml>【日志或错误截图】【可选】
-
我们知道,Netconf协议分为四层,自下而上分别为:传输层、消息层、操作层和内容层。其中最上层的内容层承载了各种配置数据和状态数据,使用Yang语言进行建模,最终传输呈现为XML文件。那么Yang文件和XML文件是如何转换的,数据是怎么传输的呢,如下图所示:在Yang模板中对应的字段填充上要下发的数据。按照Yang和XML的转换规则,将Yang文件中的节点转换成闭合标签,生成可以传输的XML文件。XML文件下发到设备后,设备使用Yang来校验XML文件,从而解析出配置数据。这样就完成了数据的传输。
-
python使用SAX解析xmlSAX是一种基于事件驱动的 API。利用SAX解析XML文档牵涉到两个部分: 解析器和事件处理器。解析器负责读取XML文档,并向事件处理器发送事件,如元素开始跟元素结束事件。而事件处理器则负责对事件作出响应,对传递的XML数据进行处理。<psax适于处理下面的问题:< p="">1、对大型文件进行处理;2、只需要文件的部分内容,或者只需从文件中得到特定信息。3、想建立自己的对象模型的时候。在python中使用sax方式处理xml要先引入xml.sax中的parse函数,还有xml.sax.handler中的ContentHandler。ContentHandler类方法介绍characters(content)方法调用时机:从行开始,遇到标签之前,存在字符,content 的值为这些字符串。从一个标签,遇到下一个标签之前, 存在字符,content 的值为这些字符串。从一个标签,遇到行结束符之前,存在字符,content 的值为这些字符串。标签可以是开始标签,也可以是结束标签。startDocument() 方法文档启动的时候调用。endDocument() 方法解析器到达文档结尾时调用。startElement(name, attrs)方法遇到XML开始标签时调用,name是标签的名字,attrs是标签的属性值字典。endElement(name) 方法遇到XML结束标签时调用。</psax适于处理下面的问题:<>
-
【问题来源】【必填】 中信银行总行【问题简要】【必填】 xml2.1进线,未与坐席建立会场,全程智能语音与用户互动,需求IVR录音,录音需包含IVR放音、用户音,类似智能语音邮箱留言的一个场景在XML2.1里面怎么实现【问题类别】【必填】 流程开发【AICC解决方案版本】【必填】 V3.8C23SPC010【期望解决时间】【选填】 尽快解决
-
【问题来源】【必填】 中信银行总行【问题简要】【必填】 voiceXML2.1进线转XML1.0,通过XML1.0外呼客户经理,然后事件等待,事件处理(想在这里加定时器以及判定),超时转2.1接入码重新返回2.1流程。现有的XML流程文档没看明白怎么弄,麻烦指点一下(尽量详细一点,客户侧这方面的开发经验也比较有限)【问题类别】【必填】 流程开发【AICC解决方案版本】【必填】 V3.8C23SPC010【期望解决时间】【选填】 尽快解决
-
1 问题现象这里报的是下载不到 repomd.xml,直观反应是源地址错了或者过期了,甚至是我网络出问题了。 2 问题排查网络有没有问题?百度页面是可以拉下来的,没啥问题,dns应该也没啥问题,要不然解析不了域名官方源不维护了?用浏览器去源网站看了下,是可以访问的,并且明显有repomd.xml这个文件这会是啥情况,难道是ssl不可信被拦截了(公司证书没认证这个域名)?试了一把还真是,但是一般没认证,在执行yum命令时报的是Curl error (60): SSL peer certificate or SSH remote key was not OK for https://xxxxx会很容易定位出这个问题,但是此操作系统却没有报,导致定位问题会比较模糊3 问题解决在 /etc/yum.conf里面加上sslverify=false,问题就解决了
上滑加载中
推荐直播
-
全面解析华为云EI-API服务:理论基础与实践应用指南
2024/11/29 周五 18:20-20:20
Alex 华为云学堂技术讲师
本期直播给大家带来的是理论与实践结合的华为云EI-API的服务介绍。从“主要功能,应用场景,实践案例,调用流程”四个维度来深入解析“语音交互API,文字识别API,自然语言处理API,图像识别API及图像搜索API”五大场景下API服务,同时结合实验,来加深开发者对API服务理解。
去报名 -
企业员工、应届毕业生、在读研究生共探项目实践
2024/12/02 周一 19:00-21:00
姚圣伟 在职软件工程师 昇腾社区优秀开发者 华为云云享专家 HCDG天津地区发起人
大神带你一键了解和掌握LeakyReLU自定义算子在ONNX网络中应用和优化技巧,在线分享如何入门,以及在工作中如何结合实际项目进行学习
即将直播 -
昇腾云服务ModelArts深度解析:理论基础与实践应用指南
2024/12/03 周二 14:30-16:30
Alex 华为云学堂技术讲师
如何快速创建和部署模型,管理全周期AI工作流呢?本期直播聚焦华为昇腾云服务ModelArts一站式AI开发平台功能介绍,同时结合基于ModelArts 的实践性实验,帮助开发者从理论到实验更好地理解和使用ModelArts。
去报名
热门标签