<Point TestFlag="0" id="1" name="Session Introduction">
<PracticeText> </PracticeText>
<PracticeFlag> 0 </PracticeFlag>
<ImageFile gid="1" id="1" name="d002_p001_01" type="png" />
<AudioFile gid="1" id="2" name="d002_ae_p001.mp3" type="mp3" />
</Point>
<Point TestFlag="0" id="1" name="Conversation Introduction">
<PracticeText> </PracticeText>
<PracticeFlag> 0 </PracticeFlag>
<ImageFile gid="1" id="1" name="d002_p001_02" type="png" />
<AudioFile gid="1" id="2" name="d002_ae_p002.mp3" type="mp3" />
</Point>
<Point TestFlag="0" id="1" name="Dialogue sets">
<PracticeText> </PracticeText>
<PracticeFlag> 0 </PracticeFlag>
<ImageFile gid="1" id="1" name="d002_p001_01" type="png" />
<AudioFile gid="1" id="2" name="d002_ae_p001.mp3" type="mp3" />
<ImageFile gid="1" id="1" name="d002_p001_02" type="png" />
<AudioFile gid="1" id="2" name="d002_ae_p002.mp3" type="mp3" />
</Point>
what i basically doing here is i am playing the audio files and displaying the images from the xml which are in AudioFile and ImageFile tag, but first two point i am playing when the user clicks on next button based on the i value.But when it comes to third point i am playing the 2 audio and 2 images continuously.
For playing audio files continuously i am using oncompletion listener.
My problem is
1.I want it do be dynamically acheived.
2.Suppose if we are able to acheive dynamically when in the future one or two more points is inserted in the middle of these three points also it should work
how to do this please help i am stuck
for get the length of each child tag of one point
try this this might help you
NodeList image = doc.getElementsByTagName("Point");
Element firstLevel = (Element)singleTerminalNode;
NodeList value1Nodes = (firstLevel).getElementsByTagName("ImageFile");
lengthofimage = value1Nodes.getLength();
Related
I have a following xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<Abc version="3" xmlns="urn:Abc-v3">
<Ele1>
<SubElement name ="name" description="DO">
<Node version="C" siteURL="https://example.com" />
<Client>
<ClientId>1</ClientId>
<ClientSecret>Yes</ClientSecret>
</Client>
</SubElement>
<SubElement name ="SharePointOLDev1" description="DEV1">
<Node version="C" siteURL="https://example.com" />
<Local>
<LocalId>id</LocalId>
<Password>password</Password>
</Local>
</SubElement>
<SubElement name="AS" description="wow">
<DB connection="connection" />
</SubElement>
</Ele1>
<Ele2>
<Content ID="A" co="LD">
<Description>Simple Docs</Description>
<Serve
Lib1="TEST"
Lib2="yes"
Lib3="yes"
Lib4="no"
Lib5="no"
Lib6="name">
<Hole enabled="false" count="200" />
<Fol enabled="false" count="100" />
<Role enabled="No" validate="false" />
<FetchFilenameAttribute connection="SAP-AS" delay="3" />
</Serve>
</Content>
<Content ID="B" co="OL">
<Description>Simple Docs </Description>
<Serve
Lib1="TEST"
Lib2="yes"
Lib3="yes"
Lib4="no"
Lib5="no"
Lib6="name"">
<Hole enabled="false" count="200" />
<Fol enabled="false" count="100" />
<Role enabled="No" validate="false" />
</Serve>
</Content>
</Ele2>
<Ele3>
<CNode attr="hai" attr1="bye" />
</Ele3>
</Abc>
I need to parse this XML file and assign values to its corresponding class objects.Which is the best option to parse such an xml file.
JAXB sounds good to me but the POJOs were already written by someone and now i will have to rewrite and deploy them.ALso teh xml file has some errors while running xjc command.
DOM approach seems to be very cumbersome n error prone.
Please suggest.
PS:Kindly excuse my beginner level knowledge.
the JDK project comes with SAX(Simple API for XML) accessible by importing org.xml.sax.*.
You may take a look at this https://www.tutorialspoint.com/java_xml/java_sax_parse_document.htm for an introduction to the subject.
My VoiceXML provider, Nexmo, seems not to handle the xml:lang="es-ES" attribute in the root vxml (This is generated by Rivr with a context.setLanguage("es-ES") in my Dialog)
I want Nexmo to use a spanish TTS engine but as I am using Rivr, I can't see where I can specify that I want the "prompt" to include, for example, xml:lang="es-es-female", so it generates VoiceXML:
<prompt xml:lang="es-es-female">
Hola.
</prompt>
interaction().addPrompt() only accepts the SpeechSynthesis object which does not allow (as far as I see) language options.
I've also tried include SSML in the SpeechSynthesis object (using a DocumentFragment as I see in Rivr Javadoc) but that won't work. Probably Nexmo does not support SSML.
Any workarounds? (A part from changing to a better VoiceXML provider)
Thanks a lot!!!
If you only want to play a message without getting input from the user, use can use the Message class:
//Play a synthesis message in another language
Message message = new Message("synthesis-french-message",
new SpeechSynthesis("Ceci est un message."));
message.setLanguage("fr-CA");
DialogueUtils.doTurn(message, context);
If you need to specify the language for a prompt in an Interaction, this can be done with the InteractionBuilder. The setLanguage() method can be used before the addPrompt() method. Multiple languages can be used within the same interaction:
Interaction interaction = OutputTurns.interaction("multilingual-interaction")
.setLanguage("es-ES")
.addPrompt(new SpeechSynthesis("Holá."))
.setLanguage("fr-CA")
.addPrompt(new SpeechSynthesis("Bonjour."))
.build(new SpeechRecognition(new GrammarReference("grammar.grxml")),
Duration.seconds(2));
DialogueUtils.doTurn(interaction, context);
If you don't want to use the builder, you can do it by hand but it's much longer:
List<Interaction.Prompt> prompts = new ArrayList<Interaction.Prompt>();
Interaction.Prompt spanishPrompt = new Interaction.Prompt(new SpeechSynthesis("Holá."));
spanishPrompt.setLanguage("es-ES");
prompts.add(spanishPrompt);
Interaction.Prompt frenchPrompt = new Interaction.Prompt(new SpeechSynthesis("Bonjour."));
frenchPrompt.setLanguage("fr-CA");
prompts.add(frenchPrompt);
SpeechRecognition speechRecognition = new SpeechRecognition(new GrammarReference("grammar.grxml"));
FinalRecognitionWindow finalRecognitionWindow = new FinalRecognitionWindow(speechRecognition,
Duration.seconds(2));
Interaction interaction2 = new Interaction("multilingual-interaction2",
prompts,
finalRecognitionWindow);
DialogueUtils.doTurn(interaction2, context);
The output VoiceXML is:
<?xml version="1.0" encoding="UTF-8"?>
<vxml application="/rivr-cookbook-message-language/dialogue/root/efe10575-1766-48fb-9e13-572a771bc5f4" version="2.1"
xmlns="http://www.w3.org/2001/vxml">
<script>application.rivr.localErrorHandling = false; application.rivr.inputTurn = {};</script>
<form id="form">
<block name="prompt0">
<prompt bargein="false" xml:lang="es-ES">Holá.</prompt>
</block>
<block name="prompt1">
<prompt bargein="false" xml:lang="fr-CA">Bonjour.</prompt>
</block>
<field name="recognition">
<grammar mode="voice" src="grammar.grxml" />
<property name="timeout" value="2000ms" />
</field>
<filled mode="any">
<script>application.rivr.addRecognitionResult()</script>
<goto next="#submitForm" />
</filled>
</form>
<catch>
<if cond="_event.substring(0, 5) == "error"">
<if cond="application.rivr.localErrorHandling">
<goto next="#fatalErrorForm" />
<else />
<script>application.rivr.localErrorHandling=true</script>
</if>
</if>
<script>application.rivr.addEventResult(_event, _message)</script>
<goto next="#submitForm" />
</catch>
<form id="fatalErrorForm">
<block>
<exit />
</block>
</form>
<form id="submitForm">
<block>
<var expr="application.rivr.toJson(application.rivr.inputTurn)" name="inputTurn" />
<if cond="application.rivr.hasRecording(application.rivr.inputTurn)">
<var expr="application.rivr.inputTurn.recordingMetaData.data" name="recording" />
<assign expr="undefined" name="application.rivr.inputTurn.recordingMetaData.data" />
<submit enctype="multipart/form-data" method="post" namelist="inputTurn recording"
next="/rivr-cookbook-message-language/dialogue/efe10575-1766-48fb-9e13-572a771bc5f4/0/multilingual-interaction2" />
<else />
<submit method="post" namelist="inputTurn"
next="/rivr-cookbook-message-language/dialogue/efe10575-1766-48fb-9e13-572a771bc5f4/0/multilingual-interaction2" />
</if>
</block>
</form>
</vxml>
I am currently developing a system that uses the following format of XML files to for configuration purposes:
<?xml version="1.0" encoding="utf-8"?>
<Branch>
<Department>
<Door id="1" enabled="true"/>
<Door id="2" enabled="true"/>
</Department>
<Department>
<Door id="3" enabled="true"/>
<Door id="4" enabled="false"/>
</Department>
<Department>
....
</Branch>
Do you know how could I parse this XML file?
I have been looking for other answers but I could only get it to work till the Department node. It isn't interpreting the Door node level.
I'm parsing xml file and trying to create model from it. I'm using Simple XML library. My xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<root cycles_count="2">
<shifts>
<shift id="0" name="first"/>
<shift id="1" name="second"/>
<shift id="2" name="third"/>
<shift id="3" name="fourth"/>
</shifts>
<cycles>
<cycle name="A" start_date="1334620800000">
<cycle_shift id="0" />
<cycle_shift id="0" />
<cycle_shift id="1" />
</cycle>
<cycle name="B" start_date="1334620800000">
<cycle_shift id="1" />
<cycle_shift id="1" />
<cycle_shift id="2" />
</cycle>
</cycles>
</root>
Is there any way how to create object reference from cycle_shift to shift based on the same id? I want to achieve something like this (simplified version):
#Root
public class Shift {
#Attribute
int id;
#Attribute
String name;
}
#Root
public class Cycle {
#ElementList
List<Shift> shifts; // shifts connected by id's
}
Change of xml schema is possible too. Thanks in advance.
Cycle through the Shifts and create those objects
Create a dictionary with the id of the Shift as the key and the Shift itself as the value
Loop through all your Cycles and create those objects
When creating the List of Shifts belonging to that Cycle, just reference the id from the Cycle's property and look up the Shift from the dictionary you created earlier and add it to the list.
Would that work?
You can set the name attribute optional on Shift, and get rid of cycle_shift and use only shift instead
<?xml version="1.0" encoding="utf-8"?>
<root cycles_count="2">
<shifts>
<shift id="0" name="first"/>
<shift id="1" name="second"/>
<shift id="2" name="third"/>
<shift id="3" name="fourth"/>
</shifts>
<cycle name="B" start_date="1334620800000">
<cycle_shift id="1" />
<cycle_shift id="1" />
<cycle_shift id="2" />
</cycle>
And your pseudo code will be like this: (I'm using the inline modifier)
#Root
public class Cycle {
#ElementList(inline=true)
List<Shift> shifts; // shifts connected by id's
}
I Have problem with Spring Webflow. My flow XML definition is:
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd" parent="changeLang">
<input name="hash" required="true"/>
<action-state id="decideAction">
<set name="flowScope.goTo" value ="verifyActionService.verifyHash(hash)" />
<transition to="${goTo}" ></transition>
</action-state>
<view-state id="correctVerify" view="registered" model="userAddressesForm">
<transition on="addPhoneNumber" to="correctVerify">
<evaluate expression="verifyActionService.addPhoneNumber(userAddressesForm)" />
</transition>
<transition on="deletePhoneNumber" to="correctVerify">
<evaluate expression="verifyActionService.deletePhoneNumber(userAddressesForm, requestParameters.deleteNumber)" />
</transition>
</view-state>
<view-state id="notCorrectVerify" view="register"></view-state>
</flow>
The method verifyHash return a state id equal "correctVerify" like this:
public String verifyHash(String hash) {
return "correctVerify";
}
When I run it, a get an error like this:
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalArgumentException: Cannot find state with id '${goTo}' in flow 'verify' -- Known state ids are 'array<String>['decideAction', 'correctVerify', 'notCorrectVerify', 'start']'
at org.springframework.webflow.engine.Flow.getStateInstance(Flow.java:348)
at org.springframework.webflow.engine.support.DefaultTargetStateResolver.resolveTargetState(DefaultTargetStateResolver.java:60)
at org.springframework.webflow.engine.Transition.execute(Transition.java:217)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.execute(FlowExecutionImpl.java:391)
at org.springframework.webflow.engine.impl.RequestControlContextImpl.execute(RequestControlContextImpl.java:214)
at org.springframework.webflow.engine.TransitionableState.handleEvent(TransitionableState.java:119)
Can anybody help me?
The to attribute of transition takes a string literal. If you want to combine string literals and EL, you need to use a template expression:
<transition to="#{goTo}"/>
Information about the two different types of expression can be found in this section of the documentation.
Also, are you sure you need to be returning a view-state name from your service layer? The general pattern for <action-state> is you call a method using <evaluate> and then define different transitions to different states based on the result of the <evaluate>... similar to a switch statement. Take a look at this section on action states.