473,500 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

changing the "markup" of a node

hi,

I have an xmlFile
<code>
<rows>
<row>
<PRODUCT-TYPE>bike</PRODUCT-TYPE>
<PRODUCT-DATE>01/01/2004</PRODUCT-DATE>
<ADDED-NODE>"blah"<ADDED-NODE />
</row>
<PRODUCT-TYPE>Car</PRODUCT-TYPE>
<PRODUCT-DATE>01/01/2003</PRODUCT-DATE>
<ADDED-NODE>"blah"<ADDED-NODE />
</row>
</rows>
</code>

I want to change the markup of the PRODUCT-TYPE node.

I want to change it to:
<ProductType>
So, my file would become

<code>
<row>
<ProductType>bike</ProductType
<PRODUCT-DATE>01/01/2004</PRODUCT-DATE>
<ADDED-NODE>1stCollectionItemText<ADDED-NODE />
</row>
etc
</code>

I can obtain the nodes no problem.
However, I have tried the:
1) .InnerXml property
2) .ReplaceChild method
3) OuterXml property (Which I don't think I can use because it is read-only)

can someone tell me how to change the markup..I'm struggling.

many thanks,
yogi

--
Message posted via http://www.dotnetmonster.com
Nov 12 '05 #1
3 1194


chris yoker via DotNetMonster.com wrote:

I have an xmlFile
<code>
<rows>
<row>
<PRODUCT-TYPE>bike</PRODUCT-TYPE>
<PRODUCT-DATE>01/01/2004</PRODUCT-DATE>
<ADDED-NODE>"blah"<ADDED-NODE />
</row>
<PRODUCT-TYPE>Car</PRODUCT-TYPE>
<PRODUCT-DATE>01/01/2003</PRODUCT-DATE>
<ADDED-NODE>"blah"<ADDED-NODE />
</row>
</rows>
</code>

I want to change the markup of the PRODUCT-TYPE node.

I want to change it to:
<ProductType>
So, my file would become

<code>
<row>
<ProductType>bike</ProductType
<PRODUCT-DATE>01/01/2004</PRODUCT-DATE>
<ADDED-NODE>1stCollectionItemText<ADDED-NODE />
</row>
etc
</code>

I can obtain the nodes no problem.
However, I have tried the:
1) .InnerXml property
2) .ReplaceChild method
3) OuterXml property (Which I don't think I can use because it is read-only)

can someone tell me how to change the markup..I'm struggling.


If you are using the DOM then you need to create a new element e.g.
XmlElement newElement = xmlDocument.createElement("ProductType");
then append the contents of the existing element to the new element e.g.
while (oldElement.HasChildNodes) {
newElement.AppendChild(oldElement.FirstChild);
}
then replace the old element with the new e.g.
oldElement.ParentNode.ReplaceChild(newElement, oldElement);
--

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

I am not sure how I obtain the "oldElement"
I think that I do something along the lines of:
<code>
Dim nodeList As XmlNodeList = xmlDoc.SelectNodes("Rows/row/PRODUCT-TYPE")

'And then replace the element, with the code you kindly sent.
</code>

the problem is that the above "xmlDoc.SelectNodes" xPath query returns an
EMPTY nodeList.
Yet, If I specify the xPath as follows, then it returns some rows:

<code>
Dim nodeList As XmlNodeList = xmlDoc.SelectNodes("Rows/row")
</code>

I am not sure what is going on.Given the structure of my xml, how should I
obtain the "oldElement" node?
Sorry to ask again, but I'm still finding mt feet :-)

yogi

<code>
<rows>
<row>
<PRODUCT-TYPE>bike</PRODUCT-TYPE>
<PRODUCT-DATE>01/01/2004</PRODUCT-DATE>
<ADDED-NODE>"blah"<ADDED-NODE />
</row>
<PRODUCT-TYPE>Car</PRODUCT-TYPE>
<PRODUCT-DATE>01/01/2003</PRODUCT-DATE>
<ADDED-NODE>"blah"<ADDED-NODE />
</row>
</rows>
</code>

--
Message posted via http://www.dotnetmonster.com
Nov 12 '05 #3
thanks Martin, I managed to find the problem..I have so many transforms
going on that I was losing track of the format of the xml.
Problem solved.
yogi

--
Message posted via http://www.dotnetmonster.com
Nov 12 '05 #4

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

Similar topics

1
3284
by: Ahmad Noori | last post by:
I have a form and in the form, I have a drop down box. Based on what the user selects, i want to display different input boxes. Here is my drop down box: <td> <select name="reptype"...
0
2183
by: Karl Smith | last post by:
Headless <invalid_address@dna.ie> wrote in reply to Christoph Paeper <crissov@gmx.net>: > Semantically <span>this</span> is 100% identical to: > Semantically <div>this</div> is 100% identical...
2
5353
by: ivowel | last post by:
dear css wizards: I have a document that has some annotations, which I sometimes want included, sometimes not. <div class="myannotation">some text</div> is there a css mechanism to tell the...
8
10623
by: Lian | last post by:
Hi all, It is a newbie's question about html tag "img". The attributes "title" and "alt" for "img" seems having the same function. So what is the main difference between them? Can i use them at...
17
1977
by: Will Hartung | last post by:
I have a table for a report. It can get wide, but that's no big deal. I don't mind that it can get wide. What I do mind, though, is the browser doing its damndest to smash the thing down to get...
2
14781
by: DartmanX | last post by:
I doubt this is possible, but I want to ask, just in case it is. I have a project going using Google Maps. This project spits out an HTML page template for people to post to their website and...
37
4150
by: Jan Wagner | last post by:
Hi, can't figure this one out, what's the CSS way to specify the language? In HTML it would be simply an lang="xx" attribute, or XHTML xml:lang="xx", but, how about in CSS? This would be...
3
9877
by: ano | last post by:
Hi, Anyone knows how to get "xmlns" value from XML file? For example, how to check that this xml file has a xmlns or not? Or how to read the xmlns value? <bookstore...
7
1255
by: david.deridder | last post by:
Hi, I would like to specify in my XSD that the "Documentation" element can be added everywhere in the XML document. A bit like the xs:documentation node. How can i declare this in my XSD? ...
0
7136
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
7018
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
7232
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
7397
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...
1
4923
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...
0
4611
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...
0
3110
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...
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.