on 05-12-2015 7:43 AM
I have an recursive function to read XML documents using PBDOM
Now I want to add some new elements with or without an prefix depending on the original xml document.
everything looks like ok but I miss the xml-prefix in the new added elemens in the new document.
...
ls_type = pbdom_obj_array[ll_loop].getname()
...
CHOOSE CASE ls_type
CASE "nichtangeboten"
SELECT "lv_lohn", "lv_sonstiges", "lv_betrag"
INTO :lv_lohn, :lv_sonstiges, :lv_betrag
FROM "lvpositionen" WHERE "lv_nummer" = :onlv_daten.lv_nummer and "lv_baustellenr" = :onlv_daten.projektnr;
if NOT isNull(lv_betrag) and lv_betrag <> 0 then
pbdom_obj.RemoveContent(pbdom_obj_array[ll_loop])
//ns_prefix = pbdom_obj.GetQualifiedName()
PBDOM_ELEMENT pbdom_elem0, pbdom_elem1, pbdom_elem2, pbdom_elem3, pbdom_elem4
pbdom_elem0 = Create PBDOM_ELEMENT
ns_prefix = pbdom_obj.GetNamespacePrefix ()
//ns_prefix examle: on
ns_uri = pbdom_obj.GetNamespaceUri()
pbdom_elem1 = Create PBDOM_ELEMENT
pbdom_elem2 = Create PBDOM_ELEMENT
pbdom_elem3 = Create PBDOM_ELEMENT
pbdom_elem4 = Create PBDOM_ELEMENT
if isNUll(lv_lohn) then lv_lohn = 0.00
if isNUll(lv_sonstiges) then lv_sonstiges = 0.00
if isNUll(lv_betrag) then lv_betrag = 0.00
pbdom_elem0.SetName("preis")
//what I want is <on:preis>10.00</on:preis>
//but I get <preis>10.00</preis>
//wrong, adds an attribute not the prefix 😞
/* if ns_prefix > ' ' and ns_uri > ' ' then
pbdom_elem0.AddNamespaceDeclaration(ns_prefix, ns_uri)
end if
*/
pbdom_elem1.SetName("preisanteil1")
pbdom_elem1.AddContent(f_changecharacters(string(lv_lohn, "0.00"), ',', '.'))
pbdom_elem0.AddContent (pbdom_elem1)
pbdom_elem2.SetName("preisanteil2")
pbdom_elem2.AddContent(f_changecharacters(string(lv_sonstiges, "0.00"), ',', '.'))
pbdom_elem0.AddContent (pbdom_elem2)
pbdom_elem3.SetName("gesamt")
pbdom_elem3.AddContent(f_changecharacters(string(lv_betrag, "0.00"), ',', '.'))
pbdom_elem0.AddContent (pbdom_elem3)
pbdom_obj.AddContent (pbdom_elem0)
pbdom_elem4.SetName("pospreis")
pbdom_elem4.AddContent(f_changecharacters(string(lv_betrag, "0.00"), ',', '.'))
pbdom_obj.AddContent (pbdom_elem4)
destroy pbdom_elem0
destroy pbdom_elem1
destroy pbdom_elem2
destroy pbdom_elem3
destroy pbdom_elem4
end if
CASE "preis"
...
I think you have to go with SetNamespace (), after doing an AddNamespaceDeclaration() at a higher level).
hth
Arnd
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks a lot!
Here is the right code...
pbdom_elem4 = Create PBDOM_ELEMENT | ||||||||||||||
if isNUll(lv_lohn) then lv_lohn = 0.00 | ||||||||||||||
if isNUll(lv_sonstiges) then lv_sonstiges = 0.00 | ||||||||||||||
if isNUll(lv_betrag) then lv_betrag = 0.00 | ||||||||||||||
pbdom_elem0.SetName("preis") | ||||||||||||||
if ns_prefix > ' ' and ns_uri > ' ' then | ||||||||||||||
pbdom_elem0.SetNamespace(ns_prefix, ns_uri, false) | ||||||||||||||
end if |
....
SetNamespace() was correct to add the Prefix. 🙂
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.