Ecrion Software Inc. Homepage
Forum Home Forum Home > XF Designer > FAQ
  New Posts New Posts RSS Feed: Namespaces problem
  FAQ FAQ  Forum Search   Register Register  Login Login

Namespaces problem

 Post Reply Post Reply
Author
Message / View First Unread Post
admin View Drop Down
Admin Group
Admin Group


Joined: 19 May 2008
Posts: 69
Post Options Post Options   Quote admin Quote  Post ReplyReply Direct Link To This Post Topic: Namespaces problem
    Posted: 09 Nov 2009 at 8:58am
Q: When we are testing the trial version we've found a problem: the app says there are a problem of namespace in the XML file that we used:

<SetGESYS xmlns="http://www.sii.cl/SiiDte">
<Extras>
    <subtotal_afecto>740000</subtotal_afecto>
    <fono_emp>56-32 389103</fono_emp>
</Extras>
</SetGESYS>

---------------------

A: Your XML uses the default namespace (that is, without a prefix) for all elements. Let's assume your XML looked like this:

<SetGESYS>
<Extras>
    <subtotal_afecto>740000</subtotal_afecto>
    <fono_emp>56-32 389103</fono_emp>
</Extras>
</SetGESYS>

You could use the following XPath to return all Extras elements: '//Extras'. However, if you run this XPath in your original document (where xmlns="http://www.sii.cl/SiiDte"), it will not return any values.

The reason for that is that '//Extras' will return all Extras elements that have not been declared in a namespace.

To solve this, either remove the namespace from your XML file, or, add a namespace prefix for all elements:

<x:SetGESYS xmlns:x="http://www.sii.cl/SiiDte">
<x:Extras>
    <x:subtotal_afecto>740000</x:subtotal_afecto>
    <x:fono_emp>56-32 389103</x:fono_emp>
</x:Extras>
</x:SetGESYS>

See also: http://www.edankert.com/defaultnamespaces.html

Edited by florinv - 02 Oct 2010 at 7:17am
Back to Top
BVS View Drop Down
Newbie
Newbie
Avatar

Joined: 09 Sep 2011
Location: Hyderabad
Posts: 11
Post Options Post Options   Quote BVS Quote  Post ReplyReply Direct Link To This Post Posted: 17 Nov 2011 at 6:15am

Nice Article! Smile

I've doubt regarding Namespace.
In my XML, There are as many as 5 namespaces like edx0,edx1,edx2,edx3,edx4 which heirarchically driven.
eg:
<edx0:Data xmlns:edx0="...">
    <edx1:XInfo xmlns:edx1="...">
       <edx2:XXInfo xmlns:edx2="...">
          ...
       <edx2:XXInfo>
       ...
    </edx1:XInfo>
 
    <edx1:YInfo xmlns:edx1="...">
       <edx2:YXInfo xmlns:edx2="...">
          ...
       <edx2:YXInfo>
        ...
    </edx1:YInfo>

    <edx1:ZInfo xmlns:edx1="...">
       <edx2:ZXInfo xmlns:edx2="...">
          <edx3:ZXXInfo xmlns:edx3="...">
              <Info xmlns:SOAP-ENV="..." xmlns="..." xmlns:xsd="..." xmlns:soap="..." xmlns:xsi="...">
                 <Value>5</Value>
              </Info>
          </edx3:ZXXInfo> 
           ...
       <edx2:ZXInfo>
        ...
    </edx1:ZInfo>
 
</edx0:Data>
 
As Shown in above XML, The Red font coloured namespaces are my problem.
Note:
   <Info> tag in the above XML is not having prefixxed name(xxx:Info) and its child elements too, as you can see it above.
 
I thought of transforming(using XSLT) the above sample XML without namespaces first and later solving with namespaces. I replaced all names '<edo:' with '<' and  '</edo:' with '</', similarly edx1,edx2 and so on...
 
My Problem in the Replaced XML(i.e., XML Without namespaces):
 
1) when i tried to get Value i.e., <xsl:value-of select="Data/ZInfo/ZXInfo/ZXXInfo/Info/Value"/>
    The output shows nothing, But when i remove { xmlns:SOAP-ENV="..." xmlns="..." xmlns:xsd="..." xmlns:soap="..." xmlns:xsi="..." }, the namespaces Igot the output value as '5'.
    
    a) Why it didn't work with the above braced namespace?
     
     If I don't want to remove that braced Namespace Line in my '<Info>' tag Then
 
    b) How Can i get the Output Value as '5'?
 
2) If i want to transform XML with namespaces.
 
    c) Do i need to specify Corresponding namespaces for their respectives tags everytime i use the tags?
 
    Like.,
          <xsl:value-of select="edx0:Data/edx1:ZInfo/edx2:ZXInfo/edx3:ZXXInfo/Info/Value"/>
 
    d) Or else any Alternative for that?
 
if you don't understand my a), b), c) and d) Queries? I can explain them in detail.
 
Thanks in Advance!
 
 
 
 
Back to Top
radup View Drop Down
Admin Group
Admin Group
Avatar
Adminstrator

Joined: 19 May 2008
Posts: 90
Post Options Post Options   Quote radup Quote  Post ReplyReply Direct Link To This Post Posted: 17 Nov 2011 at 9:04am
Hi BVS,

1.) The element "Info" is in default namespace defined by xmlns="...". You will need to remove only the default namespaces (i.e. xmlns="..."). 
After doing this you will have the following select:
<xsl:value-of select="/edx0:Data/edx1:ZInfo/edx2:ZXInfo/edx3:ZXXInfo/Info/Value"/>
2. If you don't want to remove the default namespace you will need define in xsl a namespace prefix with the same namespace uri as default namespace.
Lets say that we have the following xml:
<edx0:Data xmlns:edx0="www.mynamespace.com/edx0">
    <edx1:ZInfo xmlns:edx1="www.mynamespace.com/edx1">
       <edx2:ZXInfo xmlns:edx2=www.mynamespace.com/edx2">
          <edx3:ZXXInfo xmlns:edx3="www.mynamespace.com/edx3">
              <Info xmlns="www.mynamespace.com/Info" >
                 <Value>5</Value>
              </Info>
          </edx3:ZXXInfo> 
       <edx2:ZXInfo>
    </edx1:ZInfo>
</edx0:Data>

In stylesheet we will have the following select:
<xsl:value-of select="/edx0:Data/edx1:ZInfo/edx2:ZXInfo/edx3:ZXXInfo/info:Info/info:Value" xmlns:info="www.mynamespace.com/Info" />
Note the xmlns:info="www.mynamespace.com/Info" declaration.



Edited by radup - 17 Nov 2011 at 9:05am
Back to Top
BVS View Drop Down
Newbie
Newbie
Avatar

Joined: 09 Sep 2011
Location: Hyderabad
Posts: 11
Post Options Post Options   Quote BVS Quote  Post ReplyReply Direct Link To This Post Posted: 18 Nov 2011 at 12:21am
Thnx a lot  it solved my Problem
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.69
Copyright ©2001-2010 Web Wiz

This page was generated in 0.064 seconds.