Getting Particular Values From XML Document

Multi tool use
Multi tool use
The name of the pictureClash Royale Clan(#23URR8PPP)


Getting Particular Values From XML Document



I'm trying to get some values from an XML Document.

Here is the Xml Document that being generated from DevExpress


<?xml version="1.0" encoding="ISO-8859-1"?>
<XtraSerializer version="15.2.5.0">
<Items>
<Item1 SelectedStencils="" CanvasSizeMode="AutoSize" PageSize="40000,40000"
Theme="Office" ItemKind="DiagramRoot" Size="40000,40000">
<Children>
<Item1 ItemKind="DiagramShape" Size="100,75" Shape="BasicShapes.Rectangle"
Position="19500,19440"/>
<Item2 ItemKind="DiagramShape" Size="100,90" Shape="BasicShapes.Triangle"
Position="19540,19660"/>
<Item3 ItemKind="DiagramConnector" EndPoint="19590,19660"
BeginPoint="19550,19515" EndItem="1" BeginItem="0" Points="19550,19650
19590,19650" EndArrow="Filled90"/>
<Item4 ItemKind="DiagramShape" Size="100,75" Shape="BasicShapes.Rectangle"
Position="19940,19440"/>
<Item5 ItemKind="DiagramConnector" EndPoint="19940,19477.5"
BeginPoint="19600,19477.5" EndItem="3" BeginItem="0" Points=""
EndArrow="Filled90"/>
<Item6 ItemKind="DiagramConnector" EndPoint="19940,19477.5"
BeginPoint="19590,19660" EndItem="3" BeginItem="1" Points="19590,19525
19930,19525 19930,19478" EndArrow="Filled90"/>
</Children>
</Item1>
</Items>
</XtraSerializer>



I'm trying to get the values "BeginItem" & "EndItem" from the "DiagramConnector" part.

I tried to get these values with the DevExpress API BeginItem -- EndItem

but each time I try, the values are always Null even though when the data is saved, its not null in the XML Document.

So I figured getting the values directly from the XML document would be the best/only way.

Here is how I'm trying to get the values from the xml document.
keep in mind that there could be a million DiagramConnection Objects.


class Program
{
static readonly string FolderLocation = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\Diagram Samples";
static readonly string FileName = "d.xml";

static void Main(string args)
{
string FullPath = System.IO.Path.Combine(FolderLocation, FileName);

using (XmlDocumentCreator xmlDocument = new XmlDocumentCreator(FullPath))
{
string data = xmlDocument.ReadDocument.ToString();
if (data.Contains("BeginItem") && data.Contains("EndItem"))
{
string xpath = "Items/Item1SelectedStencils/Children";
var nodes = xmlDocument.XMLDocument.SelectNodes(xpath);

foreach (XmlNode childrenNode in nodes)
{
Console.Write(childrenNode.SelectSingleNode("//BeginItem").Value);
}
}
}

Console.ReadKey();
}
}



And Here is my XML Document class I created,
I know its not correct for this project as SelectNodes requires an XmlDocument, its just for testing.


class XmlDocumentCreator : IDisposable
{
public XmlDocument XMLDocument { get; set; }

// <summary>
/// XmlDocument Creator
/// </summary>
/// <param name="xmlDocumentPath">xmlPath</param>
public XmlDocumentCreator(string xmlDocumentPath)
{
XMLDocument = new XmlDocument();
XMLDocument.Load(xmlDocumentPath);
}

/// <summary>
/// Returns An Xml Document
/// Which Can Then Be Read.
/// </summary>
/// <returns></returns>
public XElement ReadDocument
{
get
{
if (XMLDocument != null)
{
return XElement.Parse(XMLDocument.InnerXml);
}
throw new Exception("XML Document Object Was Not Created");
}
}


/// <summary>
/// Will Dispose The XML Document
/// And Also Call The Garbage Collector.
/// </summary>
public void Dispose()
{
if (XMLDocument != null)
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.SuppressFinalize(this);
GC.Collect();
Console.WriteLine("XML Document Object Disposed");
}
}
}



In a perfect world, once I can get the values that are needed during the loop for each value on I could put them to an anonymous type and do with them whatever.





//Items/Item1[@SelectedStencils]/Children may get you started.
– mjwills
yesterday


//Items/Item1[@SelectedStencils]/Children





it certainly has gotten me one step closer thats for sure, cheers mate
– AndrewE
yesterday









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

sy I,zGp
rWgWmD HDzdEd6641m,gVjMDznXa3,iA,999RdxpJHlPHkP

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

415 Unsupported Media Type while sending json file over REST Template