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 -
'ForXML
-
Dim objDom
-
Dim objRoot
-
Dim objField
-
Dim objFieldValue
-
Dim objcolName
-
Dim objattTabOrder
-
Dim objPI
-
Dim objRow
-
Sub GenerateXML()
-
-
Dim intA As Integer
-
Dim intB As Integer
-
Dim Sheet1 As String
-
Dim ws As Worksheet
-
' Dim shtArray() As String
-
Dim shtArrayXML() As String
-
Dim Answer As String
-
Dim LRow As Integer: LRow = 3
-
Dim Row_Max As Integer
-
Dim LColumnField() As String
-
Dim LColumnFieldValue() As String
-
-
-
'Declaration
-
Application.ScreenUpdating = False
-
Msg10 = "Are you sure you want to Generate XML?"
-
' Asking whether to Generate XML or not
-
Answer = MsgBox(Prompt:=Msg10 _
-
& vbCr & vbCr & "Click Yes to Generate." _
-
& vbCr & vbCr & "Click No to quit.", _
-
Title:="Confirmation Message", _
-
Buttons:=vbYesNoCancel + vbDefaultButton3)
-
'Answer = Confirmation
-
If Answer <> vbYes Then
-
Exit Sub
-
Else
-
-
'Call the function to prepare the Output XML file
-
PrepareXML (1)
-
-
Workbook_Name = "Metadata Utility.xlsm"
-
totalfields = 0
-
-
'LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
-
'Column till which nodes have to be created
-
LastColumn = 27
-
For LColumn = 2 To LastColumn
-
ReDim Preserve LColumnField(totalfields + 1)
-
If Cells(5, LColumn).Value <> "" Then
-
LColumnField(totalfields) = Cells(5, LColumn).Value
-
totalfields = totalfields + 1
-
End If
-
Next LColumn
-
-
totalfields = 0
-
-
For LColumn = 2 To LastColumn
-
ReDim Preserve LColumnFieldValue(totalfields + 1)
-
LColumnFieldValue(totalfields) = Cells(7, LColumn).Value
-
totalfields = totalfields + 1
-
Next LColumn
-
-
'Sub to prepare nodes of XML
-
ConvertTexttoXML LColumnField, LColumnFieldValue, totalfields, "Test"
-
-
'Prepare final part of the XML
-
PrepareXML (2)
-
End If
-
End Sub
-
-
'Function to prepare XML first and end parts
-
Function PrepareXML(xmlPart)
-
-
Select Case xmlPart
-
-
Case 1
-
-
'Instantiate the Microsoft XMLDOM.
-
Set objDom = CreateObject("Microsoft.XMLDOM")
-
' Set objDom = CreateObject("MSXML2.DOMDocument.6.0")
-
-
objDom.preserveWhiteSpace = True
-
-
'Create your root element and append it to the XML document.
-
Set objRoot = objDom.createElement("DRMUtility")
-
objDom.appendChild objRoot
-
-
Dim objattTabOrder
-
Set objattTabOrder = objDom.createAttribute("xml:space")
-
objattTabOrder.Text = "preserve"
-
objRoot.setAttributeNode objattTabOrder
-
-
-
Case 2
-
'Prepare the XML
-
Set objPI = objDom.createProcessingInstruction("xml", "version='1.0'")
-
-
objDom.InsertBefore objPI, objDom.ChildNodes(0)
-
-
'Send the XML back after adding encoding -ISO-8859-1 to XML tag to read all languages
-
xmlOutPut = Replace(objDom.XML, "?>", " encoding=""ISO-8859-1""?>", 1, 1)
-
-
-
-
Set SendDoc = CreateObject("Microsoft.XMLDOM")
-
SendDoc.async = False
-
SendDoc.LoadXML (xmlOutPut)
-
-
Dim FolderName As String
-
With Application.FileDialog(msoFileDialogFolderPicker)
-
.AllowMultiSelect = Faslse
-
.Title = "Choose a folder path to save the file"
-
.Show
-
On Error Resume Next
-
FolderName = .SelectedItems(1)
-
Err.Clear
-
On Error GoTo 0
-
End With
-
-
If FolderName <> "" Then
-
XMLFileName = "DRMUtility"
-
currentTime = Format(Now, "DDMMYYYYhhmmss")
-
currentXMLFile = XMLFileName & "_" & currentTime & ".xml"
-
SendDoc.Save (FolderName & "\" & currentXMLFile)
-
End If
-
-
Set SendDoc = Nothing
-
Set objDom = Nothing
-
-
End Select
-
-
End Function
-
-
'Sub to prepare nodes of XML
-
Sub ConvertTexttoXML(OutputFields, OutputVal, totalfields, xmlSheetNodeName)
-
-
Dim totalnofields
-
Dim i: i = 0
-
-
fieldpart = "drm:"
-
totalnofields = CInt(totalfields)
-
fieldpart = "drm:"
-
-
Set objRow = objDom.createElement(xmlSheetNodeName)
-
For i = 0 To totalnofields - 1
-
Set objField = objDom.createElement(fieldpart & OutputFields(i))
-
objField.Text = OutputVal(i)
-
objRow.appendChild objField
-
Next
-
-
objRoot.appendChild objRow
-
-
End Sub
-
-
-
11 4728
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.
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.
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.
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.
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.
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.
You need to use the createNode method that will allow you to specify a namespace.
Can you please tell me how to write it?
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. :)
zmbd, no idea how to declare the namespace.
Could you please tell me.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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"
|
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...
|
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...
|
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...
|
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...
|
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'...
|
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/"...
|
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:...
|
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...
|
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>
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |