473,761 Members | 2,440 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Class and Node InsertAfter

Hi,
I’ve made a class to help me accomplish some things faster but I’m having
problems inserting nodes. I’ve tried many different ways, but with no
success. This is a very stripped down version of what I’m trying to do. I
know that I’m simply missing some basic understanding, so hopefully someone
can enlighten me.

Public Class MYXMLCLASS
Public theXMLDocument As New XmlDataDocument
Public myXPath As String

Sub New()
myXPath = "/"
Exit Sub
End Sub

Public Function addDeclaration( ) As String
Dim myDeclaration As XmlDeclaration
myDeclaration = theXMLDocument. CreateXmlDeclar ation("1.0", Nothing,
Nothing)
myDeclaration = theXMLDocument. InsertBefore(my Declaration,_
theXMLDocument. DocumentElement )
lastNode = CType(myDeclara tion, XmlNode)
Return True
End Function

Public Function addNode(ByVal myXMLString As String) As String
Dim myNewDoc As New XmlDataDocument
Dim myReturnNode As XmlNode
Dim myCurrentNode As XmlNode =
theXMLDocument. SelectSingleNod e(myXPath)
myNewDoc.LoadXm l(myXMLString)
myReturnNode = theXMLDocument. DocumentElement .InsertAfter(my NewDoc,_
myCurrentNode)

Return myCurrentNode.O uterXml
End Function

This is called in another place
Dim myPageInfoXML As New MYXMLCLASS
myPageInfoXML.s etPath("/") // sets myXPath
myPageInfoXML.a ddDeclaration()
myPageInfoXML.a ddNode("<test>b lah</test>")

Nov 12 '05 #1
2 3155


Kael wrote:

I’ve made a class to help me accomplish some things faster but I’m having
problems inserting nodes. I’ve tried many different ways, but with no
success. This is a very stripped down version of what I’m trying to do. I
know that I’m simply missing some basic understanding, so hopefully someone
can enlighten me.

Public Class MYXMLCLASS
Public theXMLDocument As New XmlDataDocument
Public myXPath As String

Sub New()
myXPath = "/"
Exit Sub
End Sub

Public Function addDeclaration( ) As String
Dim myDeclaration As XmlDeclaration
myDeclaration = theXMLDocument. CreateXmlDeclar ation("1.0", Nothing,
Nothing)
myDeclaration = theXMLDocument. InsertBefore(my Declaration,_
theXMLDocument. DocumentElement )
lastNode = CType(myDeclara tion, XmlNode)
Return True
End Function

Public Function addNode(ByVal myXMLString As String) As String
Dim myNewDoc As New XmlDataDocument
Dim myReturnNode As XmlNode
Dim myCurrentNode As XmlNode =
theXMLDocument. SelectSingleNod e(myXPath)
myNewDoc.LoadXm l(myXMLString)
myReturnNode = theXMLDocument. DocumentElement .InsertAfter(my NewDoc,_
myCurrentNode)

Return myCurrentNode.O uterXml
End Function

This is called in another place
Dim myPageInfoXML As New MYXMLCLASS
myPageInfoXML.s etPath("/") // sets myXPath
myPageInfoXML.a ddDeclaration()
myPageInfoXML.a ddNode("<test>b lah</test>")


I am not sure what you want to achieve but the XPath expression /
selects the root node which is the XML document itself in the DOM so I
don't think it makes much sense to try to call

Dim myCurrentNode As XmlNode =
theXMLDocument. SelectSingleNod e(myXPath)
myNewDoc.LoadXm l(myXMLString)
myReturnNode =
theXMLDocument. DocumentElement .InsertAfter(my NewDoc,_
myCurrentNode)

It is also not clear where you create a documentElement at all.

If you want to start from scratch to create a new XmlDocument by parsing
a string of XML markup then you can simply use the LoadXml method.
If you have a need after that to parse some snippet of XML markup in a
string to insert stuff in the document then use a DocumentFragmen t and
set its InnerXml e.g. (pseudo code)
Dim DocFrag as XmlDocumentFrag ment
DocFrag = theXMLDocument. CreateDocumentF ragment()
DocFrag.InnerXm l = "<test>blah </test>"
theXMLDocument. DocumentElement .AppendChild(Do cFrag)
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2


"Martin Honnen" wrote:
I am not sure what you want to achieve but the XPath expression /
selects the root node which is the XML document itself in the DOM so I
don't think it makes much sense to try to call

Dim myCurrentNode As XmlNode =
theXMLDocument. SelectSingleNod e(myXPath)
myNewDoc.LoadXm l(myXMLString)
myReturnNode =
theXMLDocument. DocumentElement .InsertAfter(my NewDoc,_
myCurrentNode)

It is also not clear where you create a documentElement at all.

If you want to start from scratch to create a new XmlDocument by parsing
a string of XML markup then you can simply use the LoadXml method.
If you have a need after that to parse some snippet of XML markup in a
string to insert stuff in the document then use a DocumentFragmen t and
set its InnerXml e.g. (pseudo code)
Dim DocFrag as XmlDocumentFrag ment
DocFrag = theXMLDocument. CreateDocumentF ragment()
DocFrag.InnerXm l = "<test>blah </test>"
theXMLDocument. DocumentElement .AppendChild(Do cFrag)
--

Martin Honnen
http://JavaScript.FAQTs.com/


I guess I striped it down too much. The idea is to insert nodes where ever I
need to with in the intance's 'theXMLDocument ' property. The 'myXPath'
property acts as a sort of cursor, so that when I call my 'addNode' (or any
method) the class instance has a point of reference to work from.

Ignore the DocumentElement in the statement... that was left over from
playing around with it.. although, I obviously don't understand it's
function too well.

I'll play around with the CreateDocumentF ragment to see if I can get this to
work.. and I may try doing a switch on node types (ie figuring out what
'myXPath' actually points to) and going from there.

If I'm still confusing.. sorry. I don't post very often.
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2041
by: dinks | last post by:
Hi, I'm new to C++ and have been assigned a task which i dont completely understand. Any help would be greately appreciated. Here is the problem: The class "linkedListType" use the "assert" facility. I am to get rid of them and replace them with exceptions. I need to create a "linkedListException" class that's declared and implemented in my "linkedListType" class. This class needs to inherit from the base "exception" class and return...
4
5887
by: The Kiddie | last post by:
Hi, I am having major headaches with XmlNode.InsertAfter. This is the format of my XML document <?xml version="1.0" encoding="utf-8"?> <Team name="Team"> <Players> <Player> <name> GK</name> <age> 28 </age>
8
488
by: chris yoker via DotNetMonster.com | last post by:
hiya, I succesfully return a "nodeList" thru the "xmlDoc.SelectNodes" method. This nodeList is taken from a repetitive, uniform xml doc. I can successfully append a child node at the correct position using the following code: <code> <!--Node successfully inserted into corrrect position in nodeList(0)--> nodeList(0).InsertAfter(additionalNode, nodeList(0).ChildNodes(5))
1
1321
by: PaulF | last post by:
I am trying to do add a repeating XmlNode into and existing XML document and have had some problems. The base XML: <Property> <Premises> <Endorsement> <ShortWording/> <Wording/>
1
1701
by: qwerty | last post by:
Hello, I'm having problems accessing elements in the polygon class every time I try to move the iterator it stays at the same element... code: #include <iostream> using namespace std;
1
1604
by: Patrick | last post by:
Hi, I have a xml file like this: <?xml version="1.0"?> <home> <page name="Test1" id="1"> <page name="Pagetest1" id="2" src="test1.htm"></page> <page name="pagetest3" id="3" src="test2.htm"></page> </page>
3
6882
by: davidfahy | last post by:
Hi all, Let say I have the following XML file: <Books> <book id = "1"> <title>ASP.NET</title> <isbn>121212</isbn> <price>32.65</price> </book>
18
1330
by: Brandon | last post by:
I have a question about manipulating a document. Suppose for example that I had a table like this: <table> <tr id="row1"> <td>R1C1</td> </tr> <tr> <td>R2C1</td> </tr>
0
1153
by: romcab | last post by:
Hello expert, I would like to ask how can I add a parent node and child node simultaneously. I try this code; //create parent node XmlElement ^elem = doc->CreateElement( args ); //elem->InnerText = "Rom"; //Add the node
0
9522
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
9336
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,...
0
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9765
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...
0
8770
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7327
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
6603
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
5215
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...
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.