![]() |
Namespaces problem |
Post Reply
|
| Author | |||
admin
Admin Group
Joined: 19 May 2008 Posts: 68 |
Post Options
Quote Reply
Topic: Namespaces problemPosted: 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 |
|||
![]() |
|||
BVS
Newbie
Joined: 09 Sep 2011 Location: Hyderabad Posts: 11 |
Post Options
Quote Reply
Posted: 17 Nov 2011 at 6:15am |
||
|
Nice Article! 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!
|
|||
![]() |
|||
radup
Admin Group
Adminstrator Joined: 19 May 2008 Posts: 83 |
Post Options
Quote Reply
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:
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:
In stylesheet we will have the following select:
Note the xmlns:info="www.mynamespace.com/Info" declaration. Edited by radup - 17 Nov 2011 at 9:05am |
|||
![]() |
|||
BVS
Newbie
Joined: 09 Sep 2011 Location: Hyderabad Posts: 11 |
Post Options
Quote Reply
Posted: 18 Nov 2011 at 12:21am |
||
|
Thnx a lot it solved my Problem
|
|||
![]() |
|||
Post Reply
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |