473,395 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problem with namespace in XML document

Hello All,

I have the following XML document : (for ease of understanding i am just
posting a part of it)

Base XML
------------
<?xml version="1.0"?>
<ROOT>
<REPLY>DRAWLIST_INFO_REQUEST</REPLY>
<DECLARE_PREFIX xmlns:ENC="http://www.syswareinc.com/ENCOUNTR"
xmlns:SPECIMEN="http://www.syswareinc.com/SPECLOG">
<ACCESSION>
<ENC:NUMBER>58967</ENC:NUMBER>
<SPECIMEN>

<SPECIMEN:SPECIMENID><![CDATA[S0656363XX1]]></SPECIMEN:SPECIMENID>
<SPECIMEN:SPECSTATUS><![CDATA[Collection
Pending]]></SPECIMEN:SPECSTATUS>
</SPECIMEN>
<ENC:STATUS><![CDATA[Waiting for Specimen]]></ENC:STATUS>
</ACCESSION>
</DECLARE_PREFIX>
</ROOT>

This is the base xml. After some processing on the client side, the status
of the specimen is changed and for this we get a xml file from the server.
The contents of the xml file sent by the server is as follows :

Reply from server with updated specimen status - Reply XML
----------------------------------------------------------------------
<?xml version='1.0' ?>
<ROOT>
<DECLARE_PREFIX xmlns:ENC="http://www.syswareinc.com/ENCOUNTR"
xmlns:SPECIMEN="http://www.syswareinc.com/SPECLOG">
<ACCESSION>
<ENC:NUMBER>58967</ENC:NUMBER>
<SPECIMEN>
<SPECIMEN:SPECIMENID><![CDATA[S0656363XX1]]></SPECIMEN:SPECIMENID>
<SPECIMEN:SPECSTATUS><![CDATA[Collected]]></SPECIMEN:SPECSTATUS>
</SPECIMEN>
<ENC:STATUS><![CDATA[Waiting for Specimen]]></ENC:STATUS>
</ACCESSION>
</DECLARE_PREFIX>
</ROOT>

The reply xml is read and the ACCESSION tag and it's childnodes are taken
into a XmlNodelist. This XmlNodelist is passed as a parameter in the
UpdateXML method. In this method, the ENC:NUMBER is matched and the base xml
is updated with the contents of the xml file got from the server. Following
code shows how we do this :

Public Sub ReadCollectionsXml()
Dim LOC_XML_Document As XmlDocument
Dim LOC_RootElement As XmlElement
Dim LOC_XMLNode_Accession As XmlNodeList = Nothing

LOC_XML_Document = New XmlDocument
LOC_XML_Document.Load(Reply XML)
LOC_RootElement =
CType(LOC_XML_Document.DocumentElement.Item("DECLA RE_PREFIX"), XmlElement)
LOC_XMLNode_Accession = LOC_RootElement.GetElementsByTagName("ACCESSION")

If Not IsNothing(LOC_XMLNode_Accession) Then
UpdateXML(LOC_XMLNode_Accession)
End If
End Sub

Public Sub UpdateXML(ByVal AccessionsToBeUpdated As XmlNodeList)

Dim LOC_XML_Document As New XmlDocument
Dim LOC_RootElement As XmlElement
Dim LOC_XMLNodeList As XmlNodeList
Dim LOC_NodeItem As XmlNode
Dim LOC_EachItem As Integer = 0
Dim LOC_EachAccession As Integer = 0
Dim LOC_XMLNode_Accession As XmlNode

LOC_XML_Document.Load(Base XML)
'Referring to the Root node
LOC_RootElement = LOC_XML_Document.DocumentElement
'XML node list to store all available accession number
LOC_XMLNodeList = LOC_RootElement.GetElementsByTagName("ENC:NUMBER")

'To visit each item of node list
For LOC_EachItem = 0 To AccessionsToBeUpdated.Count - 1
'To store each node
LOC_NodeItem = LOC_XML_Document.CreateNode(XmlNodeType.Element,
"ACCESSION", String.Empty)
'To assign content
LOC_NodeItem.InnerXml = AccessionsToBeUpdated.Item(LOC_EachItem).InnerXml
For LOC_EachAccession = 0 To LOC_XMLNodeList.Count - 1
'To store each accession node from login XML
LOC_XMLNode_Accession = LOC_XMLNodeList.Item(LOC_EachAccession)
'To check for the accession number
If
LOC_XMLNode_Accession.InnerText.Equals(LOC_NodeIte m.ChildNodes(0).InnerText)
Then
'Replacing the <ACCESSIONtag

LOC_XMLNode_Accession.ParentNode.ParentNode.Replac eChild(LOC_NodeItem,
LOC_XMLNode_Accession.ParentNode)
'Exiting from the inner loop
Exit For
End If
Next
Next

'Disposing the node list
LOC_XMLNodeList = Nothing

'Saving the updated xml file
LOC_XML_Document.Save(E_XML_FILEPATH & GLO_DRAWLIST_XML_NAME)
End Sub

This process is working absolutely fine but the problem is that after the
ReplaceChild method is called, the namespaces also get inserted in the tags
as shown below :

Base xml after the updation process
------------------------------------------
<?xml version="1.0"?>
<ROOT>
<DECLARE_PREFIX xmlns:ENC="http://www.syswareinc.com/ENCOUNTR"
xmlns:SPECIMEN="http://www.syswareinc.com/SPECLOG">
<ACCESSION>
<ENC:NUMBER
xmlns:ENC="http://www.syswareinc.com/ENCOUNTR">58967</ENC:NUMBER>
<SPECIMEN>
<SPECIMEN:SPECIMENID
xmlns:SPECIMEN="http://www.syswareinc.com/SPECLOG"><![CDATA[S0656363XX1]]></SPECIMEN:SPECIMENID>
<SPECIMEN:SPECSTATUS
xmlns:SPECIMEN="http://www.syswareinc.com/SPECLOG"><![CDATA[Collected]]></SPECIMEN:SPECSTATUS>
</SPECIMEN>
<ENC:STATUS
xmlns:ENC="http://www.syswareinc.com/ENCOUNTR"><![CDATA[Waiting for
Specimen]]></ENC:STATUS>
</ACCESSION>
</DECLARE_PREFIX>
</ROOT>

Can anyone please guide me as i don't want the namespaces to be inserted as
attributes of the tags ? Looking forward to your response.
Regards,
Viral
Aug 22 '06 #1
1 1315
I have solved this problem by using ImportNode method of XMLDocument class.
"Viral" wrote:
Hello All,

I have the following XML document : (for ease of understanding i am just
posting a part of it)

Base XML
------------
<?xml version="1.0"?>
<ROOT>
<REPLY>DRAWLIST_INFO_REQUEST</REPLY>
<DECLARE_PREFIX xmlns:ENC="http://www.syswareinc.com/ENCOUNTR"
xmlns:SPECIMEN="http://www.syswareinc.com/SPECLOG">
<ACCESSION>
<ENC:NUMBER>58967</ENC:NUMBER>
<SPECIMEN>

<SPECIMEN:SPECIMENID><![CDATA[S0656363XX1]]></SPECIMEN:SPECIMENID>
<SPECIMEN:SPECSTATUS><![CDATA[Collection
Pending]]></SPECIMEN:SPECSTATUS>
</SPECIMEN>
<ENC:STATUS><![CDATA[Waiting for Specimen]]></ENC:STATUS>
</ACCESSION>
</DECLARE_PREFIX>
</ROOT>

This is the base xml. After some processing on the client side, the status
of the specimen is changed and for this we get a xml file from the server.
The contents of the xml file sent by the server is as follows :

Reply from server with updated specimen status - Reply XML
----------------------------------------------------------------------
<?xml version='1.0' ?>
<ROOT>
<DECLARE_PREFIX xmlns:ENC="http://www.syswareinc.com/ENCOUNTR"
xmlns:SPECIMEN="http://www.syswareinc.com/SPECLOG">
<ACCESSION>
<ENC:NUMBER>58967</ENC:NUMBER>
<SPECIMEN>
<SPECIMEN:SPECIMENID><![CDATA[S0656363XX1]]></SPECIMEN:SPECIMENID>
<SPECIMEN:SPECSTATUS><![CDATA[Collected]]></SPECIMEN:SPECSTATUS>
</SPECIMEN>
<ENC:STATUS><![CDATA[Waiting for Specimen]]></ENC:STATUS>
</ACCESSION>
</DECLARE_PREFIX>
</ROOT>

The reply xml is read and the ACCESSION tag and it's childnodes are taken
into a XmlNodelist. This XmlNodelist is passed as a parameter in the
UpdateXML method. In this method, the ENC:NUMBER is matched and the base xml
is updated with the contents of the xml file got from the server. Following
code shows how we do this :

Public Sub ReadCollectionsXml()
Dim LOC_XML_Document As XmlDocument
Dim LOC_RootElement As XmlElement
Dim LOC_XMLNode_Accession As XmlNodeList = Nothing

LOC_XML_Document = New XmlDocument
LOC_XML_Document.Load(Reply XML)
LOC_RootElement =
CType(LOC_XML_Document.DocumentElement.Item("DECLA RE_PREFIX"), XmlElement)
LOC_XMLNode_Accession = LOC_RootElement.GetElementsByTagName("ACCESSION")

If Not IsNothing(LOC_XMLNode_Accession) Then
UpdateXML(LOC_XMLNode_Accession)
End If
End Sub

Public Sub UpdateXML(ByVal AccessionsToBeUpdated As XmlNodeList)

Dim LOC_XML_Document As New XmlDocument
Dim LOC_RootElement As XmlElement
Dim LOC_XMLNodeList As XmlNodeList
Dim LOC_NodeItem As XmlNode
Dim LOC_EachItem As Integer = 0
Dim LOC_EachAccession As Integer = 0
Dim LOC_XMLNode_Accession As XmlNode

LOC_XML_Document.Load(Base XML)
'Referring to the Root node
LOC_RootElement = LOC_XML_Document.DocumentElement
'XML node list to store all available accession number
LOC_XMLNodeList = LOC_RootElement.GetElementsByTagName("ENC:NUMBER")

'To visit each item of node list
For LOC_EachItem = 0 To AccessionsToBeUpdated.Count - 1
'To store each node
LOC_NodeItem = LOC_XML_Document.CreateNode(XmlNodeType.Element,
"ACCESSION", String.Empty)
'To assign content
LOC_NodeItem.InnerXml = AccessionsToBeUpdated.Item(LOC_EachItem).InnerXml
For LOC_EachAccession = 0 To LOC_XMLNodeList.Count - 1
'To store each accession node from login XML
LOC_XMLNode_Accession = LOC_XMLNodeList.Item(LOC_EachAccession)
'To check for the accession number
If
LOC_XMLNode_Accession.InnerText.Equals(LOC_NodeIte m.ChildNodes(0).InnerText)
Then
'Replacing the <ACCESSIONtag

LOC_XMLNode_Accession.ParentNode.ParentNode.Replac eChild(LOC_NodeItem,
LOC_XMLNode_Accession.ParentNode)
'Exiting from the inner loop
Exit For
End If
Next
Next

'Disposing the node list
LOC_XMLNodeList = Nothing

'Saving the updated xml file
LOC_XML_Document.Save(E_XML_FILEPATH & GLO_DRAWLIST_XML_NAME)
End Sub

This process is working absolutely fine but the problem is that after the
ReplaceChild method is called, the namespaces also get inserted in the tags
as shown below :

Base xml after the updation process
------------------------------------------
<?xml version="1.0"?>
<ROOT>
<DECLARE_PREFIX xmlns:ENC="http://www.syswareinc.com/ENCOUNTR"
xmlns:SPECIMEN="http://www.syswareinc.com/SPECLOG">
<ACCESSION>
<ENC:NUMBER
xmlns:ENC="http://www.syswareinc.com/ENCOUNTR">58967</ENC:NUMBER>
<SPECIMEN>
<SPECIMEN:SPECIMENID
xmlns:SPECIMEN="http://www.syswareinc.com/SPECLOG"><![CDATA[S0656363XX1]]></SPECIMEN:SPECIMENID>
<SPECIMEN:SPECSTATUS
xmlns:SPECIMEN="http://www.syswareinc.com/SPECLOG"><![CDATA[Collected]]></SPECIMEN:SPECSTATUS>
</SPECIMEN>
<ENC:STATUS
xmlns:ENC="http://www.syswareinc.com/ENCOUNTR"><![CDATA[Waiting for
Specimen]]></ENC:STATUS>
</ACCESSION>
</DECLARE_PREFIX>
</ROOT>

Can anyone please guide me as i don't want the namespaces to be inserted as
attributes of the tags ? Looking forward to your response.
Regards,
Viral
Aug 24 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Bernd Fuhrmann | last post by:
Hi! I have some trouble with some simple stupid XSLT-stuff. My stylesheet: ------------- <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0"...
2
by: Stanimir Stamenkov | last post by:
I'm trying to find out if it is permissible to include a schema document with absent target namespace to a schema with specified target namespace, and if it is, what are the rules to resolve the...
5
by: Alexander Gnauck | last post by:
Hello, i have problems with the Namespaces and the .Net XML Parser My XML looks like this: <query xmlns="jabber:iq:roster"> <item jid="srlee@localhost" name="srlee"...
6
by: trexim | last post by:
Hi, I am trying to create a Web Reference for CSTA using the URL http://www.ecma-international.org/standards/ecma-348/csta-wsdl/csta-wsdl-all-operations.wsdl Visual .Net complains that: "...
5
by: Alexis | last post by:
Hello, I have a set of classes I created from schema files using the xsd.exe tool. I'm using namespaces in the clases ( I had to because I have some classes with the same name but not the same...
9
by: Richard L Rosenheim | last post by:
I'm trying to query a XML file that was created via ADO.NET. My query wasn't returning anything, and I tracked the problem to an issue with the namespace that ADO.NET specified. When I remove the...
2
by: tomek.romanowski | last post by:
Hi ! I have problem with validating of the document with multiple namespaces. The odd thing is, that my data work O'K when I test it under XMLSpy but it doesn't work with my C# code. My first...
10
by: Opa | last post by:
I have tried for two days to solve this problem with no luck. I have a singleton class which has some events declared. When I inherit from this class the events don't seem to come along with it....
0
by: ryan | last post by:
I've been tasked with consuming a Perl web service that was written by a person in a different department of my company. The problem is it's the guy's first attempt at web services and he doesn't...
1
by: Maxim Sloyko | last post by:
Hi All! I have a little problem with XML namespaces. In my application I have two XML processors, that process the same document, one after the other. The first one looks for nodes in 'ns1'...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.