Dealing with optional XML elements
We have a template that will print certain tables based on whether or not an element is present in the incoming XML file.
I have no problem displaying these tables conditionally on XML elements that are always present (i.e. I can say <?if:element='Y'?>) but I'm running into problems when I need to display a table/field based on whether or not an element is present.
Also, when the element in question is not present, the template ignores my page break and prints the remainder of the document on the same page.
Can anyone recommend a way to accomplish the above?
Thanks.
You should use <?if:element = ''?> or <?if:element != ''?>
This should work also:
<?if:text(element)?> or <?if:not(text(element))?>
The condition is always true (false) when either the element is empty or does not
exist. Let me know, if you need to differentiate between both (probably using name() instead of text will work in this case).
If a pagebreak is inside the if statement than it is only shown when the condition is satisfied.
Hope that helps,
Klaus
Similar Messages
-
Dealing with inherited xml facts in business rules
Hello Everyone,
I encountered a problem while writing business rules for an xml input message which is of abstract type. The schema follows the xml inheritance and the structure is somewhat like -
Document (abstract)
*|*
Message (abstract)
*|*
NotificationMessage (abstract)
*|*
*|-ContractCreated (concrete)*
*|-ContractCancelled*
*|-ContractUpdate*
*|-ContractEnhance*
The input for buiness rules is a variable of type "Document". Rule wizard has generated all jaxb classes correctly.
Now when I am writing a if-then rule as below -
If Document is ContractCreated and ....
+....+
the compiler warns with message :- RUL-05162: The rule set "Ruleset1" requires fact type "ContractCreated", but this type is not part of the input.
How to deal with such xml facts where input is abstract type and rule needs to be applied on concrete definition??
Note- The incoming xml messages are instances of schema that is used across the applications hence schema cannot be modified.
Thanks,
Viv
Edited by: user564736 on Jan 21, 2013 7:23 AMCan you verify and make sure, you have sleceted the "Tree" option for the input of the Decision Function.
Look at the Following for reference:
http://docs.oracle.com/cd/E29505_01/user.1111/e10228/descfunc.htm#BCGIFGBI -
Dealing with non-database elements!!
hi all, i knew that i have to deal with non-database elements from javascript code and not from SQL code.. but i need to do some processing from SQL code and then update non-database element, how could i do this??
You should use <?if:element = ''?> or <?if:element != ''?>
This should work also:
<?if:text(element)?> or <?if:not(text(element))?>
The condition is always true (false) when either the element is empty or does not
exist. Let me know, if you need to differentiate between both (probably using name() instead of text will work in this case).
If a pagebreak is inside the if statement than it is only shown when the condition is satisfied.
Hope that helps,
Klaus -
Matching JS XML object with Indd XML elements
Hello Scripters,
I need help ...
I have some XML from a file read into a Javascript XML object.
The object has the name "myXml", and contains:
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<imagecontainer href="C:\33415677.JPG"></imagecontainer>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description><test>Sublevel</test>An in-depth look at creating applications with XML.</description>
</book>
... and several other books
I also have some XML in Indesign, wich in my JS is known as "myTplXmlRoot".
myTplXmlRoot is defined as myTplXmlRoot = mySelection.associatedXMLElement;
What would be the best approach for matching elements of the same name in the two xml structures, and where there is a match* replace the Indesign content**, with that from the object "myXml"?
*) Match if same name, dont worry about place in hirachy
**) content might be an imageI've figured out the solution to my problem. For anyone
interested, see me code below (the xml element names are different,
but the concept is the same). -
How to deal with optional elements?
Hi,
I'm using clientgen to generate the client classes required for me to access a web service from an EJB. The web services is document-oriented and thus I just assemble the message by building up ordinary Java objects (which were generated by clientgen).
SIDStructure s = new SIDStructure();
s.setSIDUniqueReference(createUniqueRef(findCriteriaTO)); s.setSIDOtherCriteria(createSIDOther(findCriteriaTO));
where createUniqueRef and createSIDOther create the necessary objects to assign to the setters on the SIDStructure object.
If I comment out the s.setSIDUniqueReference(..) line above, the XML sent over the wire is as follows:
<SIDSearchCriteria>
..<SIDUniqueReference xsi:nil="true"/>
..<SIDOtherCriteria>
....<FamilyName>smith</FamilyName>
..<SIDOtherCriteria>
..</SIDSearchCriteria>
</SIDSearchCriteria>
But this doesn't conform to my schema. The schema says:
<xs:complexType name="SIDSearchCriteriaStructure">
..<xs:sequence>
....<xs:choice>
......<xs:element ref="SIDUniqueReference"/>
......<xs:element ref="SIDOtherCriteria"/>
....</xs:choice>
..</xs:sequence>
</xs:complexType>
So my question is, how can I get WebLogic to not output an element for a field in the client classes that isn't set? i.e. I don't want it to send the element <SIDUniqueReference xsi:nil="true"/> over the wire.
Thanks
Nick
Message was edited by:
nasmithAfter speaking to BEA support it appears as though there is a partial solution to this issue. If you add the attributes minOccurs="0" nillable="true" to the elements then the SOAP message is correct. i.e.
<xs:complexType name="SIDSearchCriteriaStructure">
<xs:sequence>
<xs:choice>
<xs:element ref="SIDUniqueReference" minOccurs="0" nillable="true"/>
<xs:element ref="SIDOtherCriteria" minOccurs="0" nillable="true"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
I say that this is only a partial fix because elements cannot have minOccurs and nillable attribtes when they are references (as opposed to named elements - e.g. <xs:element name="SIDDNA" type="RestrictedStringType"/>). This is according to XMLSpy anyway. Don't know whether it's W3C legal though.
Nick -
Can't import content with '&' in XML element
I encountered the following error msg when importing the sample XML with '&' in content of an element(for example, a URL with '&' for parameters):
<?xml version = '1.0'?>
<ROW_List>
<ROW>
...... <D3_STRU_URL>http://www.ncbi.nlm.nih.gov/mmdbsrv.cgi?form=6&db=t&Dopt=s&uid=14422
</D3_STRU_URL>
Error msg said:
<Line 19, Column 78>: XML-0100: (Fatal Error) Expected ';'.
<Line 19, Column 78>: XML-0250: (Fatal Error) Missing entity 'db'.
<Line 19, Column 85>: XML-0100: (Fatal Error) Expected ';'.
<Line 19, Column 85>: XML-0250: (Fatal Error) Missing entity 'Dopt'.
<Line 19, Column 91>: XML-0100: (Fatal Error) Expected ';'.
<Line 19, Column 91>: XML-0250: (Fatal Error) Missing entity 'uid'.
It seems that '&' is used by XDK for a kind of special purpose.
Does anybody know how to handle the problem if I really want to import content with '&'?
Thanks a lot for your help.
YihuaThe "&" character is part of the reserved word content.
Just like: <, &, >, ", ' to use these in an XML file you should
use:
< <
>“ "
‘ '
like: This is worth < $250K
will become: This is worth < $250K
Willem -
How to assign and transform or how to deal with xsd:anyType elements in 10g
Hi,
Any Update on this please...
Hi,
we are using canonical model as part of 10g, here I am not able to assign or tranform elements of type xsd:anyType to/from to other type elements. Solution with an example and quick reply is appreciated.
=========================================
Hi,
By using copy-of xslt construct again input element structure is getting copied into the target mapper file, by using value-of xsl:construct just the value is getting assigned. Can you please elaborate on how to use this xsd:anyType elements in assign and tranform activities, overall how to use these elements in 10g, while implementing the canonical model.
ex:
xsl file: by using value-of
<xsl:template match="/">
<ns1:abstractRef>
<ns1:amount>
<xsl:value-of select="/ns1:BPELProcess1ProcessRequest/ns1:input"/>
</ns1:amount>
</ns1:abstractRef>
</xsl:template>
Result:
<abstract1>
-<abstractRef xmlns:ns1="http://xmlns.oracle.com/BPELProcess1" xmlns="http://sample/test">
<ns1:amount>6556</ns1:amount>
</abstractRef>
</abstract1>
Here amount is of type xsd;anyType which is present in the abstract complexType.
xsl file: by using copy-of:
<xsl:template match="/">
<ns1:abstractRef>
<ns1:amount>
<xsl:copy-of select="/ns1:BPELProcess1ProcessRequest/ns1:input"/>
</ns1:amount>
</ns1:abstractRef>
</xsl:template>
Result:
<abstract1>
-<abstractRef xmlns:ns1="http://xmlns.oracle.com/BPELProcess1" xmlns="http://sample/test">
<ns1:amount>
<ns1:input>6556</ns1:input>
</ns1:amount>
</abstractRef>
</abstract1>
and while using it on assign activity, it is not assigning the input value to the xsd:anyType element, please provide an example on how to do this activity along with tranform.
Edited by: user12679330 on Mar 1, 2010 4:46 AM>
Try bpelx:append as a copy rule.
>
Since this thread is over three years old it will be interesting to see if OP is still waiting for a reply. ;) -
Help with counting XML elements and converting from MS SQL 2008 to ORACLE
Hello,
My ORACLE DB version is:
('Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production');
('PL/SQL Release 11.2.0.2.0 - Production');
('CORE 11.2.0.2.0 Production');
('TNS for Linux: Version 11.2.0.2.0 - Production');
('NLSRTL Version 11.2.0.2.0 - Production');
I'm trying to convert the below SQL Server 2008 query to work on Oracle. It's important to note that the XMLData column type is CLOB.
Query 1)
-- Number of validations
select br.rulename, CAST(( CAST(br.XMLData as XML)).query('count(//Validation/Expressions/Expression)') as nvarchar(50)) as "Number of //Validation/Expressions/Expression"
from AsBusinessRules br
where
DATALENGTH(br.XMLData)>10
and CAST(( CAST(br.XMLData as XML)).query('count(//Validation/Expressions/Expression)') as nvarchar(50)) not like '0'
Any help is greatly appreciated.Hi,
You can try one of these :
select br.rulename
, count(*) as "Num. of Expression"
from AsBusinessRules br
, xmltable(
'//Validation/Expressions/Expression'
passing xmltype(br.XMLData)
) x
where length(br.XMLData) > 10
group by br.rulename
having count(*) != 0
;or,
select br.rulename
, xmlcast(
xmlquery(
'count(//Validation/Expressions/Expression)'
passing xmltype(br.XMLData)
returning content
as number
) as "Num. of Expression"
from AsBusinessRules br
where length(br.XMLData) > 10
and xmlcast(
xmlquery(
'count(//Validation/Expressions/Expression)'
passing xmltype(br.XMLData)
returning content
as number
) != 0
It's important to note that the XMLData column type is CLOB.Could you consider migrating the column to XMLType datatype?
Given your version, it would be binary XML by default and therefore a lot more performant with XQueries, compared to a simple CLOB storage. -
Dealing with optional APIs in J2ME
On top of MIDP, there are optional packages that a phone may or may not support. Say, the MMAPI may not be supported by many phones.
I am trying to write an application which, after installation, either plays a video, or informs the user that "This application cannot play video on this phone".
Certainly System.getProperty("javax.microedition.media") may help, but what I am afraid of is that if an application has been compiled using "import javax.microedition.media", it may not even install on a device which doesnt support MMAPI, and all my user will get is an "Installation failed" message.
What is a solution to this. I dont want to have multiple versions of my midlet (ie, with and without MMAPI part of the code)I believe you can use the fully qualified package location to get around this. Instead of importing, refer to the class directly when you need it. (Can you make a reference to it then?)
I did some research to kinda make sure: http://discussion.forum.nokia.com/forum/archive/index.php/t-36314.html -
Hi guys!
I have a problem about "Spry.Data.XMLDataSet",
I have two xml files, "em1.xml" and "em2.xml". they have the
same structure;
The code of "em1.xml" :
<employees>
<employee id="123456">
<lastname>Smith</lastname>
<firstname>Edward</firstname>
<phone>(415) 333-0235 </phone>
<username>esmith</username>
</employee>
<employee id="127937">
<lastname>Johnson</lastname>
<firstname>Neil</firstname>
<phone>(415) 333-9475 </phone>
<username>njohnson</username>
</employee>
</employees>
and the "em2.xml" code:
<employees">
<employee id="123543">
<lastname>Davis</lastname>
<firstname>Kirk</firstname>
<phone>(415) 333-4334 </phone>
<username>kdavis</username>
</employee>
<employee id="127944">
<lastname>Miller</lastname>
<firstname>James</firstname>
<phone>(415) 333-7566 </phone>
<username>jmiller</username>
</employee>
</employees>
Now! I want to display these datas on a dynamic table.here is
my code
var ds1 = new Spry.Data.XMLDataSet("em1.xml",
"employees/employee");
var ds2 = new Spry.Data.XMLDataSet("em2.xml",
"employees/employee");
var ds3 = new Spry.Data.XMLDataSet();
ds3.data = ds1 + ds2;
<div spry:region="ds3">
<ul spry:repeatchildren="ds3">
<li spry:sort="lastname">{lastname}</li>
</ul>
</div>
finally! But It does not work! How can I combine "ds1" and
"ds2"!
------on my God! Spry have not support the method!
but I've solved it;
my code:
var ds1 = new Spry.Data.XMLDataSet("em1.xml",
"employees/employee");
var ds2 = new Spry.Data.XMLDataSet("em2.xml",
"employees/employee");
ds1.loadData();
ds2.loadData();
//ds2 addObserver
var myObj = new Object;
myObj .onPostLoad = function(dataSet,data){
dataSet.data = dataSet.data.concat(ds1.data);//concat two
array
for(var i=0; i<dataSet.data.length; i++){
dataSet.data
.ds_RowID = i;//reset ds_RowID
ds2.addObserver(myObj ); -
I am dealing with the Photoshop Elements 6 GIF animation frame delay bug. I understand there has not been a fix for some time so I want to know if one has been developed. If not what do I have to do to address this. Can I get an upgrade? What steps do I have to take and who do I deal with at Adobe for this?
The gif delay problem persisted for many versions of PSE. You can buy PSE 12, but it's silly to buy it from adobe since their upgrade price is more than the street price for the full version at big box stores and online resellers.
If your question is will adobe give you a free upgrade because of this bug, then the answer is no. -
XML Element of XML Element of XML Element (and so on...)
Here is my XML data (shorted, in a file myFile):
<LiveData>
<Voltage>
<Total>
<VoltageNow>1052</VoltageNow>
</Total>
</Voltage>
<Power>
<Total>
<PowerNow>345</PowerNow>
</Total>
</LiveData>
I would like to get the VoltageNow and PowerNow values, but the following script does not work:
tell application "System Events"
set elem1 to XML element 1 of XML file myFile /*<LiveData>
set power to XML elements of elem1 whose name is "Power"
set total to XML elements of power whose name is "Total"
set powernow to value of XML elements of total whose name is "PowerNow"
end tell
Error: System Events got an error: Can’t make {} into type string.
BTW, I don't want to use XML Element X because the order may change.
What is the correct method to traverse these elements to obtain values?AppleScript can handle the strings, but the System Events XML Suite doesn't work with text strings - it deals with the XML objects, which have name and value properties. The handler can be modified to show the names of an element, but it is just designed to work with the XML Suite.
The contents of an XML file is just text, so you can forgo System Events and just use regular text manipulation statements, or use another tool such as the Satimage XMLLib osax, which is much more robust and does include commands to display the XML object as a string.
By the way, my original handler was designed and tested in Leopard, but I discovered a Snow Leopard bug that alters the way it returns array/list contents. The following script has changes that return the functionality, in addition to a dialog handler that will display lists:
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
font-weight: normal;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px; height: 340px;
color: #000000;
background-color: #DAFFB6;
overflow: auto;"
title="this text can be pasted into the Script Editor">
on run -- example
set XMLFile to (choose file without invisibles)
show("element value:", (getXMLElement from {XMLFile, "LiveData", "Voltage", "Total", "VoltageNow"}))
end run
to show(label, something)
show an alert for something, formatting lists and records
parameters - label [text]: the alert text
something [mixed]: an item to put in the alert message
returns nothing
if something is not in {null, missing value} then
try -- show the message
if (class of something) is in {list, record} then (something as number) -- force an error
display alert label message (something as text)
on error errorMessage -- lists and records don't format very well, so cheat
set {here, there} to {(offset of "{" in errorMessage), -(offset of "}" in (reverse of text items of errorMessage) as text)}
display alert label message text here thru there of errorMessage
end try
else
display alert label message "*null or missing value*"
end if
end show
to getXMLElement from XMLItems
get the specified element from a simple XML structure by name or index
the number of items is not fixed, but must be at least 2 (the XML file and an XML element)
parameters: XMLItems [list] -
item 1 [text]: the XML file path (Finder or POSIX)
item 2 [mixed]: the XML element name or index (names are case sensitive)
item(s) 3+ [mixed]: sub item(s)
returns [list]: value of the element
try
if (count XMLItems) is less than 2 then error "getXMLElement handler: item list contains too few items"
tell application "System Events"
set theXMLData to contents of XML file ((the first item of XMLItems) as text)
-- get text of theXMLData
set theXMLElement to XML element 1 of theXMLData -- start at the root element
repeat with anItem in rest of XMLItems -- add on the sub items
set anItem to contents of anItem
try
set anItem to anItem as integer -- index number?
end try
set theXMLElement to (get XML element anItem of theXMLElement)
end repeat
try -- return the element(s)
-- return name of XML elements of theXMLElement
set theResult to value of theXMLElement -- SL built-in result variable does not get set
if theResult is missing value then error -- SL does not error on empty or missing value
return theResult
on error errorMessage number errorNumber -- the element is empty, or a list of items
log errorMessage
return value of XML elements of theXMLElement
end try
end tell
on error errorMessage number errorNumber
log errorMessage
-- return null
error "getXMLElement handler: element not found (" & errorNumber & ")"
end try
end getXMLElement</pre> -
Delete xml element not used in document
Hi,
If you have a number of texts tagged with an xml element and then delete the text, the element still exist in the structure.
You can see the element still connected to a text, by the blue diamond on the element symbol.
But i want do delete the elements that have no connection to texts, but cant find the right property to look for.
In Java script CS4.
Anyone knows?
/MikaelIf the (text) element is unplaced, its parentStory will be an XmlStory rather than a Story.
So try:
var elements = app.activeDocument.xmlElements[0].xmlElements.everyItem().getElements();
for (var i = elements.length - 1;i >= 0;i--){
if(elements[i].parentStory.constructor.name === "XmlStory"){
elements[i].remove();
This is untested. If you have tagged graphics frames it will need to be modified to not error on those.
Jeff -
Little help with complex XML data as data provider for chart and adg
Hi all,
I've been trying to think through a problem and Im hoping for
a little help. Here's the scenario:
I have complex nested XML data that is wrapped by subsequent
groupings for efficiency, but I need to determine if each inner
item belongs in the data collection for view in a data grid and
charts.
I've posted an example at the bottom.
So the goal here is to first be able to select a single
inspector and then chart out their reports. I can get the data to
filter from the XMLListCollection using a filter on the first layer
(ie the name of the inspector) but then can't get a filter to go
deeper into the structure in order to determine if the individual
item should be contained inside the collection. In other words, I
want to filter by inspector, then time and then tag name in order
to be able to use this data as the basis for individual series
inside my advanced data grid and column chart.
I've made it work with creating a new collection and then
looping through each time there is a change to the original
collection and updating the new collection, but that just feels so
bloated and inefficient. The user is going to have some buttons to
allow them to change their view. I'm wondering if there is a
cleaner way to approach this? I even tried chaining filter
functions together, but that didn't work cause the collection is
reset whenever the .refresh() is called.
If anyone has experience in efficiently dealing with complex
XML for charting purposes and tabular display purposes, I would
greatly appreciate your assistance. I know I can get this to work
with a bunch of overhead, but I'm seeking something elegant.
Thank you.Hi,
Please use the code similar to below:
SELECT * FROM DO_NOT_LOAD INTO TABLE IT_DO_NOT_LOAD.
SORT IT_DO_NOT_LOAD by WBS_Key.
IF SOURCE_PACKAGE IS NOT INITIAL.
IT_SOURCE_PACKAGE[] = SOURCE_PACKAGE[].
LOOP AT IT_SOURCE_PACKAGE INTO WA_SOURCE_PACKAGE.
V_SYTABIX = SY-TABIX.
READ TABLE IT_DO_NOT_LOAD into WA_DO_NOT_LOAD
WITH KEY WBS_Key = WA_SOURCE_PACKAGE-WBS_Key
BINARY SEARCH.
IF SY-SUBRC = 0.
IF ( WA_DO_NOT_LOAD-WBS_EXT = 'A' or WA_DO_NOT_LOAD-WBS_EXT = 'B' )
DELETE IT_SOURCE_PACKAGE INDEX V_SYTABIX.
ENDIF.
ENDIF.
ENDLOOP.
SOURCE_PACKAGE[] = IT_SOURCE_PACKAGE[].
ENDIF.
-Vikram -
How to truncate xml element to 10 characters
Hello frenz,
I've an xml element like description which is too long... I want to truncate it to some 10 characters.... please let me know howYou can use substring function to get the 10 characters like this: <?substring(element_name,1,10)?>
replace element_name with your xml element.
Thanks!
Maybe you are looking for
-
Cannot Update Decimal Places in General Settings
When I try to update the decimal points in the Administration > System Initialization > General Settings > Display path, SAP B1 gives me the following error: "Cannot update while another user is connected to the company." I am the only one on the sys
-
Iphone 6, photo library "downloading"
I purchased my iPhone 6 about a month ago, it was already backed up through Icloud and on my old iPhone 5s. Since purchasing it and updating, and restoring my camera roll has been saying downloading, when I connect it to iTunes it says that I have 90
-
Populating Description in different language
Hi, While Creating a material i want to populate the material description in different languages (German and Chinese). But the problem is how to convert the description in different languages in program. Is there any function module available for tra
-
SAP note 1941092 hasn't been updated in a while
SAP note 1941092 hasn't been updated in a while (2+ months), the last version covered is 1.2.4. At least changes for 1.25, 1.4.0 and 1.4.4 are missing. Would somebody from the UI Theme Designer team please update the SAP note and keep it up to date?
-
Making QT Movie in IPhoto???
I have a lot to learn. Can anyone tell how Iphoto can render a QT Movie of a slide show with such a reduced file size. They are unbelievably small. I can't come anywhere near achieving the small file size of an IPhoto movie using Final Cut Pro. How i