Re: Editting an XML file
- From: "David" <david.colliver.NEWS@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 17 Jan 2008 22:06:39 -0000
Sorry about all this...
I sorted it, though don't know why it is happening.
Basically, I am doing a selectNode to
/Part/PartImages/PartImage/PartRegions
Immediately after this line, I lose the data, which is really odd, so I have
come up one stage earlier and added an extra loop (this is both on the open
and save).
Works now. Was pulling my hair out with this.
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"David" <david.colliver.NEWS@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:eGfmDBVWIHA.5984@xxxxxxxxxxxxxxxxxxxxxxx
Further to my last...
It is disappearing as soon as I load the document, before I have done any
processing.
Basically, I have an overriden XmlDocument. I have put breakpoints all
over this class to ensure that nothing is being run during instantiation.
Then, I have
XDoc MyDoc = new XDoc; // XDoc is the override name of XmlDocument.
This is outside of the functions.
in my startup function I have a file open dialog to select the file.
XDoc.Load(FileName);
I then go into my command window and type...
XDoc.InnerXML and I search for a unique word in the 'missing' text and
sure enough, that whole section is gone. I have also done a selectnode and
it does not exist.
Is there a known problem with XmlDocument?
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"David" <david.colliver.NEWS@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:%232QqG1UWIHA.1532@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
Thanks for these.
I did try GetElementByTagName but gave up on that, for exactly the
problem you outlined, as I have nested elements with the same name. (I am
not controlling the name). THe method you have outlined here is similar
to what I have written already (though I have done the loop inside the
function rather than calling a seperate function to do the loop).
I have another problem now and not sure what is causing it...
A whole segment of my XML is disappearing during my save. This is really
odd as I am not reading or writing any of this section.
Basically, I am loading the XML at start-up and putting it into an
XMLDocument that is globally accessed.
I am parsing the XML similar to what you have outlined below and building
up a datatable to be used in my app.
I then display the first record.
Even without doing anything to the XML itself, when I click my save
button, I am just saving the data in exactly the opposite way that I
collect the data from the XML file, yet a good chunk is disappearing that
I am not even touching. (How confused am I?)
Based on my previous tree, there are nodes and leafs between PartImage
and PartRegions (they are earlier siblings to PartRegions (the first
level PartRegions)). This area is absolutely critical to the
functionality of the desktop version of the app and I really don't
understand why it is disappearing.
I will try and do a debug, but I don't know where the problem will lie.
Even though you haven't seen the code yet, do you know of anything that I
might have overlooked that would cause this?
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"Martin Honnen" <mahotrash@xxxxxxxx> wrote in message
news:uaZKeYTWIHA.3556@xxxxxxxxxxxxxxxxxxxxxxx
Martin Honnen wrote:
If you have elements of the same name at different levels then
GetElementsByTagName is kind of dangerous however as it gives the
elements at all levels and it flattens the hierarchy and the nesting.
In that case you might need loop through ChildNodes of a node and check
the NodeType == XmlNodeType.Element to find child elements, if needed
you can add a check for the Name.
Here is an example how you could build your own method to find child
elements of a certain name:
static ArrayList GetChildElements (XmlNode node, string name)
{
ArrayList elements = new ArrayList();
foreach (XmlNode child in node.ChildNodes)
{
if (child.NodeType == XmlNodeType.Element && child.Name == name)
{
elements.Add(child);
}
}
return elements;
}
used like this:
XmlDocument doc = new XmlDocument();
doc.LoadXml(@"<root>
<foo>
<child>
<child>
<bar></bar>
</child>
<item>value 1</item>
</child>
<whatever/>
<child>
<item>value 2</item>
</child>
</foo>
</root>");
ArrayList childElements = GetChildElements(doc.DocumentElement["foo"],
"child");
foreach (XmlNode node in childElements)
{
Console.WriteLine(node["item"].InnerText);
}
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
.
- References:
- Editting an XML file
- From: David
- Re: Editting an XML file
- From: Martin Honnen
- Re: Editting an XML file
- From: David
- Re: Editting an XML file
- From: Martin Honnen
- Re: Editting an XML file
- From: David
- Re: Editting an XML file
- From: Martin Honnen
- Re: Editting an XML file
- From: Martin Honnen
- Re: Editting an XML file
- From: David
- Re: Editting an XML file
- From: David
- Editting an XML file
- Prev by Date: Re: Editting an XML file
- Next by Date: Re: Namespace Issue with InnerXML
- Previous by thread: Re: Editting an XML file
- Next by thread: Liquid Technologies Announces Availability of Liquid XML 2008 (v6.1)
- Index(es):