473,785 Members | 2,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_PREF IX xmlns:ENC="http ://www.syswareinc. com/ENCOUNTR"
xmlns:SPECIMEN= "http://www.syswareinc. com/SPECLOG">
<ACCESSION>
<ENC:NUMBER>589 67</ENC:NUMBER>
<SPECIMEN>

<SPECIMEN:SPECI MENID><![CDATA[S0656363XX1]]></SPECIMEN:SPECIM ENID>
<SPECIMEN:SPECS TATUS><![CDATA[Collection
Pending]]></SPECIMEN:SPECST ATUS>
</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_PREF IX xmlns:ENC="http ://www.syswareinc. com/ENCOUNTR"
xmlns:SPECIMEN= "http://www.syswareinc. com/SPECLOG">
<ACCESSION>
<ENC:NUMBER>589 67</ENC:NUMBER>
<SPECIMEN>
<SPECIMEN:SPECI MENID><![CDATA[S0656363XX1]]></SPECIMEN:SPECIM ENID>
<SPECIMEN:SPECS TATUS><![CDATA[Collected]]></SPECIMEN:SPECST ATUS>
</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 ReadCollections Xml()
Dim LOC_XML_Documen t As XmlDocument
Dim LOC_RootElement As XmlElement
Dim LOC_XMLNode_Acc ession As XmlNodeList = Nothing

LOC_XML_Documen t = New XmlDocument
LOC_XML_Documen t.Load(Reply XML)
LOC_RootElement =
CType(LOC_XML_D ocument.Documen tElement.Item(" DECLARE_PREFIX" ), XmlElement)
LOC_XMLNode_Acc ession = LOC_RootElement .GetElementsByT agName("ACCESSI ON")

If Not IsNothing(LOC_X MLNode_Accessio n) Then
UpdateXML(LOC_X MLNode_Accessio n)
End If
End Sub

Public Sub UpdateXML(ByVal AccessionsToBeU pdated As XmlNodeList)

Dim LOC_XML_Documen t 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_EachAccessi on As Integer = 0
Dim LOC_XMLNode_Acc ession As XmlNode

LOC_XML_Documen t.Load(Base XML)
'Referring to the Root node
LOC_RootElement = LOC_XML_Documen t.DocumentEleme nt
'XML node list to store all available accession number
LOC_XMLNodeList = LOC_RootElement .GetElementsByT agName("ENC:NUM BER")

'To visit each item of node list
For LOC_EachItem = 0 To AccessionsToBeU pdated.Count - 1
'To store each node
LOC_NodeItem = LOC_XML_Documen t.CreateNode(Xm lNodeType.Eleme nt,
"ACCESSION" , String.Empty)
'To assign content
LOC_NodeItem.In nerXml = AccessionsToBeU pdated.Item(LOC _EachItem).Inne rXml
For LOC_EachAccessi on = 0 To LOC_XMLNodeList .Count - 1
'To store each accession node from login XML
LOC_XMLNode_Acc ession = LOC_XMLNodeList .Item(LOC_EachA ccession)
'To check for the accession number
If
LOC_XMLNode_Acc ession.InnerTex t.Equals(LOC_No deItem.ChildNod es(0).InnerText )
Then
'Replacing the <ACCESSIONtag

LOC_XMLNode_Acc ession.ParentNo de.ParentNode.R eplaceChild(LOC _NodeItem,
LOC_XMLNode_Acc ession.ParentNo de)
'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_Documen t.Save(E_XML_FI LEPATH & GLO_DRAWLIST_XM L_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_PREF IX 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:SPECI MENID
xmlns:SPECIMEN= "http://www.syswareinc. com/SPECLOG"><![CDATA[S0656363XX1]]></SPECIMEN:SPECIM ENID>
<SPECIMEN:SPECS TATUS
xmlns:SPECIMEN= "http://www.syswareinc. com/SPECLOG"><![CDATA[Collected]]></SPECIMEN:SPECST ATUS>
</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 1344
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_PREF IX xmlns:ENC="http ://www.syswareinc. com/ENCOUNTR"
xmlns:SPECIMEN= "http://www.syswareinc. com/SPECLOG">
<ACCESSION>
<ENC:NUMBER>589 67</ENC:NUMBER>
<SPECIMEN>

<SPECIMEN:SPECI MENID><![CDATA[S0656363XX1]]></SPECIMEN:SPECIM ENID>
<SPECIMEN:SPECS TATUS><![CDATA[Collection
Pending]]></SPECIMEN:SPECST ATUS>
</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_PREF IX xmlns:ENC="http ://www.syswareinc. com/ENCOUNTR"
xmlns:SPECIMEN= "http://www.syswareinc. com/SPECLOG">
<ACCESSION>
<ENC:NUMBER>589 67</ENC:NUMBER>
<SPECIMEN>
<SPECIMEN:SPECI MENID><![CDATA[S0656363XX1]]></SPECIMEN:SPECIM ENID>
<SPECIMEN:SPECS TATUS><![CDATA[Collected]]></SPECIMEN:SPECST ATUS>
</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 ReadCollections Xml()
Dim LOC_XML_Documen t As XmlDocument
Dim LOC_RootElement As XmlElement
Dim LOC_XMLNode_Acc ession As XmlNodeList = Nothing

LOC_XML_Documen t = New XmlDocument
LOC_XML_Documen t.Load(Reply XML)
LOC_RootElement =
CType(LOC_XML_D ocument.Documen tElement.Item(" DECLARE_PREFIX" ), XmlElement)
LOC_XMLNode_Acc ession = LOC_RootElement .GetElementsByT agName("ACCESSI ON")

If Not IsNothing(LOC_X MLNode_Accessio n) Then
UpdateXML(LOC_X MLNode_Accessio n)
End If
End Sub

Public Sub UpdateXML(ByVal AccessionsToBeU pdated As XmlNodeList)

Dim LOC_XML_Documen t 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_EachAccessi on As Integer = 0
Dim LOC_XMLNode_Acc ession As XmlNode

LOC_XML_Documen t.Load(Base XML)
'Referring to the Root node
LOC_RootElement = LOC_XML_Documen t.DocumentEleme nt
'XML node list to store all available accession number
LOC_XMLNodeList = LOC_RootElement .GetElementsByT agName("ENC:NUM BER")

'To visit each item of node list
For LOC_EachItem = 0 To AccessionsToBeU pdated.Count - 1
'To store each node
LOC_NodeItem = LOC_XML_Documen t.CreateNode(Xm lNodeType.Eleme nt,
"ACCESSION" , String.Empty)
'To assign content
LOC_NodeItem.In nerXml = AccessionsToBeU pdated.Item(LOC _EachItem).Inne rXml
For LOC_EachAccessi on = 0 To LOC_XMLNodeList .Count - 1
'To store each accession node from login XML
LOC_XMLNode_Acc ession = LOC_XMLNodeList .Item(LOC_EachA ccession)
'To check for the accession number
If
LOC_XMLNode_Acc ession.InnerTex t.Equals(LOC_No deItem.ChildNod es(0).InnerText )
Then
'Replacing the <ACCESSIONtag

LOC_XMLNode_Acc ession.ParentNo de.ParentNode.R eplaceChild(LOC _NodeItem,
LOC_XMLNode_Acc ession.ParentNo de)
'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_Documen t.Save(E_XML_FI LEPATH & GLO_DRAWLIST_XM L_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_PREF IX 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:SPECI MENID
xmlns:SPECIMEN= "http://www.syswareinc. com/SPECLOG"><![CDATA[S0656363XX1]]></SPECIMEN:SPECIM ENID>
<SPECIMEN:SPECS TATUS
xmlns:SPECIMEN= "http://www.syswareinc. com/SPECLOG"><![CDATA[Collected]]></SPECIMEN:SPECST ATUS>
</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
6799
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" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2
2496
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 target namespace of the components from the included schema document. I'm confused because of the rules I read in the XML Schema spec <http://www.w3.org/TR/xmlschema-1/#element-element>: > If the <element> element information item has <schema>...
5
7391
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" subscription="both"><group>contacts</group></item> <item jid="tlee@localhost" name="Troy" subscription="both"><group>contacts</group></item>
6
5623
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: " The document was understood, but it could not be processed. - The WSDL document contains links that could not be resolved. - There was an error downloading
5
10083
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 class ) Here is how a given class wil looks like. <System.Xml.Serialization.XmlRootAttribute(:="mynamespace", IsNullable:=False)> _ Public Class ClassName
9
9028
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 namespace from the XML data, the query worked. Okay, so I added code to create a XMLNamespaceManager and populate it with the namespace. Now, I'm getting this exception: Prefixes beginning with "xml" (regardless of whether the characters...
2
4566
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 'main' schema is as follows: incr2.xsd ---------- <xs:schema targetNamespace="http://vit.volvo.com/dept9272/2004/ESB"
10
2234
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. The event in the singleton class always evaluates to null even when I cleary subscribe to it. Does anyone have some sample code of how to do this, or is this not possible.
0
2373
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 know how to create the WDSL. I created web service with Visual Studio that mimics his service and after some tweaking of the soapAction in the WSDL I'm able to call his service successfully. When I use SOAPScope to look the messages being sent and...
1
3263
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' namespace, and substitutes them, according to some algorithm. After this processor is finished, it is guaranteed that there are no more 'ns1' nodes left in the tree. however 'ns1' namespace dclaration is still there, in the root node (well, I put...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.