This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > March 2004 > How do I create xml node?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How do I create xml node?
ChrisH

2004-03-30, 10:15 pm

Hello:

I need to do the following.

<Document><docid> 1</docid><files><file>c:\123\234\asd.tif</file><files><index><name>Name</name><value>MyName</value></index><index><name>IdNo</name><value>0001</value></index></Document>

Any assistance would be greatly appreciated. Thank you.

Private Sub Command1_Click()
Dim xmldoc As DOMDocument30
Dim objPI As IXMLDOMProcessingInstruction
Dim rootElement As IXMLDOMElement
Dim aElement As IXMLDOMElement
Set xmldoc = New DOMDocument30

'XML version processing instruction
Set objPI = xmldoc.createProcessingInstruction("xml", "version=""1.0""")
xmldoc.appendChild objPI

'Creating root element
Set rootElement = xmldoc.createElement("Batch")
Set xmldoc.documentElement = rootElement
'Creating and appending Number element
Set aElement = xmldoc.createElement("FileRoom")
aElement.nodeTypedValue = "Test"
rootElement.appendChild aElement

Set aElement = xmldoc.createElement("DocName")
aElement.nodeTypedValue = ""
rootElement.appendChild aElement

Set aElement = xmldoc.createElement("Institution")
aElement.nodeTypedValue = "83"
rootElement.appendChild aElement

Set aElement = xmldoc.createElement("Authority")
aElement.nodeTypedValue = "123456789"
rootElement.appendChild aElement

Set aElement = xmldoc.createElement("Cabinet")
aElement.nodeTypedValue = "Contracts"
rootElement.appendChild aElement

Set aElement = xmldoc.createElement("Type")
aElement.nodeTypedValue = "Contracts"
rootElement.appendChild aElement

Set aElement = xmldoc.createElement("Document")
rootElement.appendChild aElement

Set nde = aElement.appendChild(aElement)

'Saving the document to file c:\1.xml
xmldoc.save "c:\3.xml"

MsgBox "XML document created and saved to file c:\2.xml"

Set aElement = Nothing
Set objPI = Nothing
Set rootElement = Nothing
Set xmldoc = Nothing

End

End Sub

Dimitre Novatchev [MVP XML]

2004-03-30, 10:15 pm


"ChrisH" <anonymous@discussions.microsoft.com> wrote in message
news:2C0B6E46-AE5E-4323-8774-AA5D054AA712@microsoft.com...
> Hello:
>
> I need to do the following.
>
> <Document><docid>

1</docid><files><file>c:\123\234\asd.tif</file><files><index><name>Name</nam
e><value>MyName</value></index><index><name>IdNo</name><value>0001</value></
index></Document>
>
> Any assistance would be greatly appreciated. Thank you.


Just pass the above string as argument to the loadXML() method.


Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html



>
> Private Sub Command1_Click()
> Dim xmldoc As DOMDocument30
> Dim objPI As IXMLDOMProcessingInstruction
> Dim rootElement As IXMLDOMElement
> Dim aElement As IXMLDOMElement
> Set xmldoc = New DOMDocument30
>
> 'XML version processing instruction
> Set objPI = xmldoc.createProcessingInstruction("xml", "version=""1.0""")
> xmldoc.appendChild objPI
>
> 'Creating root element
> Set rootElement = xmldoc.createElement("Batch")
> Set xmldoc.documentElement = rootElement
> 'Creating and appending Number element
> Set aElement = xmldoc.createElement("FileRoom")
> aElement.nodeTypedValue = "Test"
> rootElement.appendChild aElement
>
> Set aElement = xmldoc.createElement("DocName")
> aElement.nodeTypedValue = ""
> rootElement.appendChild aElement
>
> Set aElement = xmldoc.createElement("Institution")
> aElement.nodeTypedValue = "83"
> rootElement.appendChild aElement
>
> Set aElement = xmldoc.createElement("Authority")
> aElement.nodeTypedValue = "123456789"
> rootElement.appendChild aElement
>
> Set aElement = xmldoc.createElement("Cabinet")
> aElement.nodeTypedValue = "Contracts"
> rootElement.appendChild aElement
>
> Set aElement = xmldoc.createElement("Type")
> aElement.nodeTypedValue = "Contracts"
> rootElement.appendChild aElement
>
> Set aElement = xmldoc.createElement("Document")
> rootElement.appendChild aElement
>
> Set nde = aElement.appendChild(aElement)
>
> 'Saving the document to file c:\1.xml
> xmldoc.save "c:\3.xml"
>
> MsgBox "XML document created and saved to file c:\2.xml"
>
> Set aElement = Nothing
> Set objPI = Nothing
> Set rootElement = Nothing
> Set xmldoc = Nothing
>
> End
>
> End Sub
>



ChrisH

2004-03-30, 10:15 pm

Hello:

I would like to create the following structure:

<Document><docid>1</docid><files><file>c:\123\234\asd.tif</file></files><index><name>Name</name><value>MyName</value></index><index><name>IdNo</name><value>0001</value></index></Document>


I have included the code that I am using below. Would someone please adjust it to accomplish my goal. Thanks.
[color=darkred]
> Private Sub Command1_Click()
> Dim xmldoc As DOMDocument30
> Dim objPI As IXMLDOMProcessingInstruction
> Dim rootElement As IXMLDOMElement
> Dim aElement As IXMLDOMElement
> Set xmldoc = New DOMDocument30
> Set objPI = xmldoc.createProcessingInstruction("xml", "version=""1.0""")
> xmldoc.appendChild objPI
> Set rootElement = xmldoc.createElement("Batch")
> Set xmldoc.documentElement = rootElement
> 'Creating and appending Number element
> Set aElement = xmldoc.createElement("FileRoom")
> aElement.nodeTypedValue = "Test"
> rootElement.appendChild aElement
> aElement.nodeTypedValue = ""
> rootElement.appendChild aElement
> aElement.nodeTypedValue = "83"
> rootElement.appendChild aElement
> aElement.nodeTypedValue = "123456789"
> rootElement.appendChild aElement
> aElement.nodeTypedValue = "Contracts"
> rootElement.appendChild aElement
> aElement.nodeTypedValue = "Contracts"
> rootElement.appendChild aElement
> rootElement.appendChild aElement
> xmldoc.save "c:\3.xml"
> Set objPI = Nothing
> Set rootElement = Nothing
> Set xmldoc = Nothing

Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews