473,403 Members | 2,270 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,403 software developers and data experts.

reference to undeclared namespace prefix: 'drm'

Please check the below code in child node I want to prefix it with "drm:" but I am getting error reference to undeclared namespace prefix: 'drm'
Please check the ConvertTexttoXml procedure
Expand|Select|Wrap|Line Numbers
  1. 'ForXML
  2.  Dim objDom
  3.  Dim objRoot
  4.  Dim objField
  5.  Dim objFieldValue
  6.  Dim objcolName
  7.  Dim objattTabOrder
  8.  Dim objPI
  9.  Dim objRow
  10. Sub GenerateXML()
  11.  
  12.     Dim intA As Integer
  13.     Dim intB As Integer
  14.     Dim Sheet1 As String
  15.     Dim ws As Worksheet
  16.    ' Dim shtArray() As String
  17.     Dim shtArrayXML() As String
  18.     Dim Answer As String
  19.     Dim LRow As Integer: LRow = 3
  20.     Dim Row_Max As Integer
  21.     Dim LColumnField() As String
  22.     Dim LColumnFieldValue() As String
  23.  
  24.  
  25.     'Declaration
  26.     Application.ScreenUpdating = False
  27.     Msg10 = "Are you sure you want to Generate XML?"
  28.     ' Asking whether to Generate XML or not
  29.     Answer = MsgBox(Prompt:=Msg10 _
  30.         & vbCr & vbCr & "Click Yes to Generate." _
  31.         & vbCr & vbCr & "Click No to quit.", _
  32.         Title:="Confirmation Message", _
  33.         Buttons:=vbYesNoCancel + vbDefaultButton3)
  34.     'Answer = Confirmation
  35.     If Answer <> vbYes Then
  36.         Exit Sub
  37.     Else
  38.  
  39.         'Call the function to prepare the Output XML file
  40.         PrepareXML (1)
  41.  
  42.                Workbook_Name = "Metadata Utility.xlsm"
  43.                 totalfields = 0
  44.  
  45.                 'LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
  46.                 'Column till which nodes have to be created
  47.                 LastColumn = 27
  48.                 For LColumn = 2 To LastColumn
  49.                     ReDim Preserve LColumnField(totalfields + 1)
  50.                 If Cells(5, LColumn).Value <> "" Then
  51.                         LColumnField(totalfields) = Cells(5, LColumn).Value
  52.                         totalfields = totalfields + 1
  53.                 End If
  54.                 Next LColumn
  55.  
  56.                 totalfields = 0
  57.  
  58.                 For LColumn = 2 To LastColumn
  59.                     ReDim Preserve LColumnFieldValue(totalfields + 1)
  60.                     LColumnFieldValue(totalfields) = Cells(7, LColumn).Value
  61.                     totalfields = totalfields + 1
  62.                 Next LColumn
  63.  
  64.                 'Sub to prepare nodes of XML
  65.                 ConvertTexttoXML LColumnField, LColumnFieldValue, totalfields, "Test"
  66.  
  67.         'Prepare final part of the XML
  68.         PrepareXML (2)
  69.     End If
  70. End Sub
  71.  
  72. 'Function to prepare XML first and end parts
  73. Function PrepareXML(xmlPart)
  74.  
  75. Select Case xmlPart
  76.  
  77.     Case 1
  78.  
  79.             'Instantiate the Microsoft XMLDOM.
  80.             Set objDom = CreateObject("Microsoft.XMLDOM")
  81.             ' Set objDom = CreateObject("MSXML2.DOMDocument.6.0")
  82.  
  83.             objDom.preserveWhiteSpace = True
  84.  
  85.              'Create your root element and append it to the XML document.
  86.              Set objRoot = objDom.createElement("DRMUtility")
  87.              objDom.appendChild objRoot
  88.  
  89.             Dim objattTabOrder
  90.             Set objattTabOrder = objDom.createAttribute("xml:space")
  91.             objattTabOrder.Text = "preserve"
  92.             objRoot.setAttributeNode objattTabOrder
  93.  
  94.  
  95.     Case 2
  96.               'Prepare the XML
  97.               Set objPI = objDom.createProcessingInstruction("xml", "version='1.0'")
  98.  
  99.              objDom.InsertBefore objPI, objDom.ChildNodes(0)
  100.  
  101.             'Send the XML back after adding encoding -ISO-8859-1 to XML tag to read all languages
  102.              xmlOutPut = Replace(objDom.XML, "?>", " encoding=""ISO-8859-1""?>", 1, 1)
  103.  
  104.  
  105.  
  106.             Set SendDoc = CreateObject("Microsoft.XMLDOM")
  107.             SendDoc.async = False
  108.             SendDoc.LoadXML (xmlOutPut)
  109.  
  110.             Dim FolderName As String
  111.                 With Application.FileDialog(msoFileDialogFolderPicker)
  112.                   .AllowMultiSelect = Faslse
  113.                   .Title = "Choose a folder path to save the file"
  114.                   .Show
  115.                   On Error Resume Next
  116.                       FolderName = .SelectedItems(1)
  117.                       Err.Clear
  118.                   On Error GoTo 0
  119.                 End With
  120.  
  121.              If FolderName <> "" Then
  122.                     XMLFileName = "DRMUtility"
  123.                     currentTime = Format(Now, "DDMMYYYYhhmmss")
  124.                     currentXMLFile = XMLFileName & "_" & currentTime & ".xml"
  125.                     SendDoc.Save (FolderName & "\" & currentXMLFile)
  126.                  End If
  127.  
  128.              Set SendDoc = Nothing
  129.             Set objDom = Nothing
  130.  
  131. End Select
  132.  
  133. End Function
  134.  
  135. 'Sub to prepare nodes of XML
  136. Sub ConvertTexttoXML(OutputFields, OutputVal, totalfields, xmlSheetNodeName)
  137.  
  138.      Dim totalnofields
  139.      Dim i: i = 0
  140.  
  141.      fieldpart = "drm:"
  142.      totalnofields = CInt(totalfields)
  143.      fieldpart = "drm:"
  144.  
  145.     Set objRow = objDom.createElement(xmlSheetNodeName)
  146.     For i = 0 To totalnofields - 1
  147.         Set objField = objDom.createElement(fieldpart & OutputFields(i))
  148.         objField.Text = OutputVal(i)
  149.         objRow.appendChild objField
  150.     Next
  151.  
  152.     objRoot.appendChild objRow
  153.  
  154. End Sub
  155.  
  156.  
  157.  
Jul 10 '13 #1
11 4728
Rabbit
12,516 Expert Mod 8TB
You are in the wrong forum. What language is this? VBA? VB6? VB.Net? Let us know and we can move it to the right forum.
Jul 11 '13 #2
zmbd
5,501 Expert Mod 4TB
Rabbit,
I'm of half a mind to simply delete this...
  • No explanation behind the code.
  • No desciption of the steps taken to troubleshoot over a 100 lines of code.
  • Does not provide the line where the error occured. Doesn't even appear to have looked up what the error means.
  • And it's posted in the wrong forum.
Jul 12 '13 #3
It's Excel VBA. Trying to create XML file based on the data in excel and getting the error reference to undeclared namespace prefix: 'drm'.
The line number where error is throwing is 141.
I want to add : after drm like <drm:></drm:>
If I am putting "drm-" then it is working fine but when I am putting "drm:" it is throwing an error.
Jul 12 '13 #4
zmbd
5,501 Expert Mod 4TB
Moved your thread to the Access/VBA forum.

Line 141 -
Please post the Exact:
Title.
Error number.
Error message.
Version of Excel you are using.
Jul 12 '13 #5
Rabbit
12,516 Expert Mod 8TB
The colon is a special character in XML. It denotes that you are using a namespace. Are you trying to use a namespace? If you are, then you need to declare it in the root element. And you need to create your nodes with that namespace. If you are not trying to use a namespace, then the colon character is not allowed.
Jul 12 '13 #6
Rabbit, Thanks for your comment.
Could you please tell me how to namespace and root element so that I can use "drm:".

Thank in advance.
Jul 13 '13 #7
Rabbit
12,516 Expert Mod 8TB
You need to use the createNode method that will allow you to specify a namespace.
Jul 13 '13 #8
Can you please tell me how to write it?
Jul 13 '13 #9
zmbd
5,501 Expert Mod 4TB
Why not take a stab at writing the code first and then posting it back for us to tweak if it doesn't work.

You'll find that with the exception of the more complex and esoteric bits of code and sql, we prefer to see the work - that we we help keep the poster within the scope of their project. :)
Jul 13 '13 #10
zmbd, no idea how to declare the namespace.
Could you please tell me.
Jul 16 '13 #11
zmbd
5,501 Expert Mod 4TB
Well, there's theory and application.
Giving the code is somewhat not in the spirit of the site, see the FAQ; however, here's a tad of information, I feel that it is very importaint to understand what it is you are trying to do before you attempt the task - maybe that's the Chemist in me, just doing things in the lab without understanding can place people in harms way... not that the code would... but I ramble.

Anyway, this is a very short read and you should understand how to do the task: XML namespace - Wikipedia

Understanding XML Namespaces
From the July 2001 issue of MSDN Magazine.

Aaron Skonnard
Namespaces are the source of much confusion in XML, especially for those new to the technology. Most of the questions that I receive from readers, students, and conference attendees are related to namespaces in one way or another. It's actually kind of ironic since the Namespaces in XML Recommendation (http://www.w3.org/TR/REC-xml-names) is one of the shorter XML specifications, coming in at just under 10 pages, excluding appendices. The confusion, however, is related to namespace semantics as opposed to the syntax outlined by the specification. To fully understand XML namespaces, you must know what a namespace is, how namespaces are defined, and how they are used. {z}
The rest of this column is dedicated to answering these three questions, both syntactically and abstractly. By the time you finish reading this, you'll understand how namespaces affect the family of XML technologies.
{z}The emphasis is mine.
Jul 16 '13 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Romeo Disca | last post by:
Hello newsgroup, i'm new to xml - what's wrong with this piece code here? i have these two files: test.xml ---- <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE a SYSTEM "test.ent"
2
by: Frank Wilson | last post by:
Is there a way to change the namespace prefix of a document? I am sending a document to an application that requires that every element be prefixed with "sm". My inbound document has every...
2
by: Dale Anderson | last post by:
I have a schema that I'm trying to read. The schema has an element named 'GrantApplication' and one with a namespace prefix named 'SF424:GrantApplication'. When I try to read this schema in, I...
5
by: SenthilSS | last post by:
My application produces XML Data files which have XML namespace qualified XML elements (nodes), but the namespace itself is not declared in the data file. My task is to read these data files in a...
4
by: jb | last post by:
I have discovered that when the WSDL is auto-generated in .NET (i.e. http://.../MyService.asmx?WSDL): * Prior to SP1, it generated xmlns:s0="http://mynamespace/" in <wsdl:definitions>, and then...
0
by: Max QRO | last post by:
I have created a web service in C# that needs to receive a SOAP request from some system I have no control over. An example of the SOAP request is given below:- <?xml version='1.0'...
1
by: Tanja Schaettler | last post by:
Hello! I have an existing SOAP message which looks like: <?xml version="1.0" encoding="UTF-8" ?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"...
2
by: scottpet | last post by:
Hi, I want to add a namespace prefix to the root node of an object I am serializing to XML. I have been reading though this article:...
3
by: Markus Bauer | last post by:
Hello, I have a problem with the namespace prefix. I need to add nodes to a xml file that is not created by me. It has a namespace with the prefix "NFD". So an already existing node looks...
2
by: Shree Naik | last post by:
Hi I have a xml file tag as below: <supr:TABLE_INFO> <supr:field> <supr:tag>seq-num</supr:tag> </supr:field> </supr:TABLE_INFO>
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
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.