Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Pro Visual Basic 2005
|
Pro Visual Basic 2005 For advanced Visual Basic coders working in version 2005. Beginning-level questions will be redirected to other forums, including Beginning VB 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Visual Basic 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 27th, 2006, 07:06 PM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default create XML element with namespace

Hi All,

I have a function. It creates an XML element with namespace "pre":


VB:
--------------------------------------------------------------------------------
Function newElement(ByVal doc As XmlDocument, _
                    ByVal Name As String, _
           Optional ByVal text As String = Nothing, _
           Optional ByVal pre As String = Nothing) As XmlElement

    Dim xmlEl As XmlElement = doc.CreateElement(pre, Name, "")
    If Not (text Is Nothing) Then xmlEl.InnerText = text
    doc.DocumentElement.AppendChild(xmlEl)
    Return xmlEl
End Function
--------------------------------------------------------------------------------


Then, I call that function in this way:
newElement(xmlDoc, "FirstName", "Peter", "pre")

I expect the result:
<pre:FirstName>Peter</FirstName>

However, the result has no "pre:", just:
<FirstName>Peter</FirstName>


Why?????


Mike

 
Old June 28th, 2006, 01:16 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Can you concatenate the arguments to get the desired results?
Code:
    Dim xmlEl As XmlElement = doc.CreateElement(, pre & ":" & Name, "")
If you hardcode strings, does this do what you want? (Perhaps the arguments’ intended purpose or use by VB is other than your understanding.) What does
Code:
    Dim xmlEl As XmlElement = doc.CreateElement("pre", "Peter", "")
do for you (just as a test of behavior)?
 
Old June 29th, 2006, 08:33 PM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Brian,

First of all, thanks for your reply.

Quote:
quote:Originally posted by BrianWren
 Can you concatenate the arguments to get the desired results?
Code:
    Dim xmlEl As XmlElement = doc.CreateElement(, pre & ":" & Name, "")
 It doesn't work. ":" cannot be part of an element name.



Quote:
quote:What does
Code:
    Dim xmlEl As XmlElement = doc.CreateElement("pre", "Peter", "")
do for you (just as a test of behavior)?
No, it doesn't work too. The output will be
Code:
<FirstName>Peter</FirstName>
Mike






Similar Threads
Thread Thread Starter Forum Replies Last Post
convert XML to XMl - Another Namespace question bonekrusher XSLT 2 July 10th, 2007 07:32 AM
Element validation in a namespace.Please see AjayLuthria XSLT 1 April 20th, 2007 11:08 AM
Converting XML to XML (making element mandatory) boondocksaint20 XSLT 8 April 28th, 2006 10:54 AM
create an element using a variable for the name brenchley XSLT 2 December 9th, 2005 09:46 AM
xml namespace and asp werD420 XML 1 August 12th, 2005 01:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.