This is the documentation for euXML 2.5 The most things are also available in euXML 2.4. When you want to use the setXML function of euXML 2.3 you have to use the discription about the setOldXML function
In euXML 2.5 are many bugs fixed, namely in the functions: deleteSpaces, solve_xPath(you can use a slsh on other places then only as seperator of two niveaus)
and the argument order in the solve_xPath function is new. To order the tags takes a long time. So when you don't espacially use the order of the tags in the document
then set order to 0.
Example:
When you wants to select the name of the author and the title of his book. The XML is the following:
<BOOKS><BOOK><AUTHOR>Tolkien</AUTHOR><TITLE>The lord of the rings</TITLE></BOOK><BOOK><AUTHOR>Rowling</AUTHOR><TITLE>Harry Potter</TITLE></BOOK></BOOKS>
Then you use the xPath: /BOOKS/BOOK/*
Now you have to set order to 1 but when you first read al AUTHOR tags with: /BOOKS/BOOK/AUTHOR and then the TITLE tags in an other sequence with: /BOOKS/BOOK/TITLE
You haven't to set order to 1 when you set it to 0 it will be faster.
Changed in euXML 2.5:
New or changed in euXML 2.4:
New in euXML 2.3 are four functions:
Functions already exists in euXML 2.0 (and so also in euXML 2.1 and euXML 2.2):
The difference between ePath and xPath are four:
This function setsthe given XMLString in the given tree, at the place given by the ePath
e.g.:
sequence mytree, xml
mytree = {}
xml = "<AAA><BBB id=2/></AAA>"
mytree = setOldXML(mytree, "", xml)
mytree = setOldXML(mytree, "BBB/", "<BBB id=1>value</BBB>")
xml in mytree is now "<AAA><BBB id=1>value</BBB></AAA>"
This function sets the given XMLString in the given tree, at the place given by the ePath.
When xmlposition is euXML_BEGIN then he starts an new session of setting an long XML string. When xmlposition is euXML_FOLLOW he goes further with setting the XML you have to give the same ePath as the first time with xmlposition is euXML_BEGIN. The last time you call setXML your xmlposition is euXML_END. You can also set the whole xml in one time xmlposition is then euXML_BEGIN + euXML_END
e.g.:
sequence mytree, xml
mytree = {}
xml = "<AAA><B"
mytree = setXML(mytree, "", xml, euXML_BEGIN)
xml = "BB id=2/></"
mytree = setXML(mytree, "", xml, euXML_FOLLOW)
xml = "AA"
mytree = setXML(mytree, "", xml, euXML_FOLLOW)
xml = "A>"
mytree = setXML(mytree, "", xml, euXML_END)
mytree = setXML(mytree, "BBB/", "<BBB id=1>value</BBB>", euXML_BEGIN + euXML_END)
xml in mytree is now "<AAA><BBB id=1>value</BBB></AAA>"
Gives the XMLString of the tree at the selected location by ePath
e.g. :
(see above)
sequence mytree, xml
xml = getXML(mytree, "BBB[1]/")
xml is now "<BBB id=1>value</BBB>"
this function changes the name of the selected tag by ePath. It returns the new tree
e.g. :
(see above)
mytree = setName(mytree, "", "HEADER")
xml = getXML(mytree, "")
xml is now "<HEADER><BBB id=1>value</BBB></HEADER>"
This function returns the name selected by the ePath.
e.g. :
(see above)
xml = getName(mytree, "*[1]/")
xml is now "BBB"
This function sets the given value to a tag selected by the ePath.
e.g. :
(see above)
mytree = setValue(mytree, "BBB/", "The new value")
xml = getXML(mytree, "*/")
xml is now "<BBB id=1>The new value</BBB>"
This function gives the value of the tag selected by ePath.
e.g. :
(see above)
xml = getValue(mytree, "*[1]/")
xml is now "The new value"
This function sets a new attribute in the selected tag, when the the attribute with name name doesn't exist. Otherwise it changes only the value to value.
e.g. :
(see above)
mytree = setAttribute(mytree, "", "kind", "nothing")
mytree = setAttribute(mytree, "BBB[1]/", "id", 3)
xml = getXML(mytree, "")
xml is now "<HEADER kind="nothing"><BBB id=3>The new value</BBB></HEADER>"
This function gives the value of the attribute name of the selected tag it gives an atom or an sequence.
e.g. :
(see above)
xml = getAttribute(mytree, "", "kind")
xml is now "nothing"
This function adds a new child tag at the end of the children of the by ePath selected tag. The tag gets the name name. When the hasn't children but a value it overwrites the value.
e.g. :
mytree = setTag(mytree, "", "BBB")
xml = getXML(mytree, "")
xml is now "<HEADER kind="nothing"><BBB id=3>The new value</BBB><BBB/></HEADER>"
This function counts the children of the selected tag with the name name. When name = "*" he counts all children.
e.g. :
integer a, b
sequence xml , mytree
mytree = {}
xml = "<A><B/><C/></A>"
mytree = setXML(mytree, "", xml, euXML_BEGIN + euXML_END)
a = countTags(mytree, "", "B")
b = countTags(mytree, "", "*")
a is now 1 and b is now 2
This function deletes the tag selected by the ePath from you XML file
e.g.:
sequence xml , mytree
mytree = {}
xml = "<A><B/><C/></A>"
mytree = setXML(mytree, "", xml, euXML_BEGIN + euXML_END)
mytree = deleteTag(mytree, "B/")
xml = getXML(mytree, "")
xml is now <A><C/><A>
This function set the current location. This is only used in solve_xPath When you gives a absolute path (beginning with a slash) it makes a new location. Otherwise it uses the setted location. You can use all kind of xPath's.
This function sets an unique xPath to an ePath. An unique xPath look likes this: /AAA[1]/*[2]
When you want to change an xPath after getting it from solve_xPath you can make an ePath with this function. Mostly you will get ePath's from solve_xPath, but you can change this.
Because also solve_xPath uses xPath_to_ePath to make the ePath's.
e.g. :
sequence ePath
ePath = xPath_to_ePath("/AAA[1]/*[2]")
ePath is now "*[2]/"
This function solves the given xPath. Itr gives a sequence of xPath's ( when giveePath = 0 otherwise ePath's) . When you have setted a location you can use this by using no slash at the begining. When order = 1 he sorts the results to the order of the opening tags in the XMLString. First the parent then his children then the next parent and his children and so on. When order is 0 then he is much faster but he doesn't order the tags. You can use this when you are sure there is only one result or when you only want to count the results.
The functions in xPath which are allowed in euXML 2.5 are:
Makes of all the value's one string.
e.g. :
string = concat("abc", "def", "ghi")
string is now "abcdefghi"
gives the part of string .
e.g. :
string = substring("abcdefghi", 4, 3)
string is now "def"
Makes a string of the given argument. It gives also when you do for example string(boolean("true")) it gives "1" and not "true", because a boolean is an integer 0 or 1. When you give that to the function string it returns the number 0 or 1 as string.
Gives the part of string before substr.
e.g. :
string = substring-before("abcdefghi", "def")
string is now "abc"
Gives the part of string after substr.
e.g. :
string = substring-after("abcdefghi", "def")
string is now "ghi"
Gives the length of a string.
e.g.:
number = string-length("abcdefghi")
number is now 9
Gives 1 (true) when substr is found in substr other wise 0 (false).
e.g. :
boolean = contains("abcdefghi", "bcd")
boolean is now 1 (this is true)
deletes the spaces left and right.
e.g. :
string = normalize-space(" abcdefghi ")
string is now "abcdefghi"
return true when string starts with substr. Otherwise false.
e.g. :
boolean = starts-with("abcdefghi", " abc")
boolean is now false or 0
Gives the number of the last tag with the name given before the predicate.
You can use this to get the new setted tag.
e.g. :
<AAA>
<BBB/>
<BBB/>
<CCC/>
<BBB/>
</AAA>
/AAA[1]/BBB[last()] selects tag /AAA[1]/BBB[3]
/AAA[1]/*[last()] selects tag /AAA[1]/*[4]
The same as last but gives the position of the current tag
e.g. :
/AAA[1]/BBB[2] is the same as /AAA[1]/BBB[position() = 2]
gives the name of the curent tag.
e.g. :
/AAA/*[name() = "BBB" and position = 2] is the same as /AAA/BBB[position() = 2]
e.g. number = ceiling(3.14) number is now 4
number = ceiling(6.67) number is now 7
e.g. : number = ceiling(3.14) number is now 3
number = ceiling(6.67) number is now 6
Makes an atom of a string.
e.g. :
number = number("-123.34")
number is now -123.34
rounds a number.
e.g. : number = ceiling(3.14) number is now 3
number = ceiling(6.67) number is now 7
Converts a number or string to a boolean. "true" -> True, "false" -> False 1 -> True, 0 -> False
Returns true
Returns false
Returns True when boolean is False
Returns False when boolean is True
Tag: in an xPath you can use spaces between operator and expressions.
In your XML file you have to write this: 'attribname="attribvalue"'
'attribname = "attribvalue"' doesn't work.
Than there are the operators 'and' and 'or'
There aren't yet mathematical operators (maybe in euXML 2.6)
Inside predicates you can't use slashes but only only one axis.
To select the CCC and the DDD tags of a BBB tag with CCC attribute id = 1:
You should use:
/AAA/BBB[CCC/@id = 1]/*
But in euXML you must use this:
/AAA/BBB/CCC[@id = 1]/parent::BBB/* or
/AAA/BBB/CCC[@id = 1]/parent::*/*
In euXML you can use '//' but there is a difference between xPath and euXML xPath:
//* selects all tags in standard xPath, but in euXML it doesn't select the root tag. To select also the root tag, you can use the xPath: '/descendant-or-self::*'
The functions works only in the predicates. But it is possible to do this by using that:
/AAA/BBB is the same as /AAA/*[name() = "BBB"]