|
Hi,
I'm new to XML coding and I've got a problem I need help with. I'm developing a model in .gmax for FSX and I'm attempting to trigger animated objects using a switch that determines which animation to run. I know the following example isn't correct, I use this illustrate what I'm trying to do:
<PartInfo>
<Name>xyz_switch</Name>
<AnimLength>100</AnimLength>
<Animation>
<Parameter>
<Code>
(L:xyz_01, bool) 100 *
(L:xyz_02, bool) 100 *
(L:xyz_03, bool) 100 *
(L:xyz_04, bool) 100 *
</Code>
</Parameter>
</Animation>
<MouseRect>
<Cursor>Hand</Cursor>
<CallbackCode>
(L:xyz_01, bool) 0 > if{ (L:xyz_01, bool) 0 } els{ 1 }
(L:xyz_02, bool) 0 > if{ (L:xyz_01, bool) 0 } els{ 1 } <if xyz_01 is has already been activated, then run xyz_02>
(L:xyz_03, bool) 0 > if{ (L:xyz_02, bool) 0 } els{ 1 }<if xyz_01 and xyz_02 have already been activated, then run xyz_03>
(L:xyz_04, bool) 0 > if{ (L:xyz_03, bool) 0 } els{ 1 }<if xyz_01, 02 and 03 have been activated, then run xyz_04>
(L:xyz_05, bool) 0 > if{ (L:xyz_04, bool) 0 } els{ 1 }<if xyz_01,02,03 and 04 have been activated, then run xyz_05>
</CallbackCode>
</MouseRect>
</PartInfo>
Up to now, I've been trudging through and figuring out the code I've needed for new parts I'm creating, but this one's got me stumped!!
Can anyone give me a hand with this?
Thanks!!
AJ
|
|
|
|
|
So what are you having difficulties with?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi,
I need an expression that will cause the program to choose between 5 variables depending on which on is already active.
Example: There are five motors. I press a button to start motor #1. If motor #1 isn't already running, then it starts. If it is already running then the #2 motor starts. If #1 and #2 motors are already running, then #3 when will start, and so on.
That's all I'm trying to do really.
Thanks!
AJ
|
|
|
|
|
I don't understand how this relates to XML
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
The program I am developing for uses XML to compile and animate objects that are placed within a game. The expression I need is real simple, I just don't know how to "word" it in code.
|
|
|
|
|
You have done nothing to clarify your question. I still don't see how this is related to XML at all or what exactly you are trying to accomplish. Don't assume everyone is standing over your shoulder looking at the code you are working with. Explain what you are doing, what you have tried, what issues you are facing and what you need help with.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I need to write code for something other than what you guys use xml for, it's for a 3D modeling program.
Apparently I posted my question on the wrong forum.
Sorry guys, you have a nice day!
|
|
|
|
|
Hello, I got a simple question and i geuss the answer will be simple to. I've just spend 8 hours looking at this but can't seem to solve it.
I Got a gridview that shows data from an exsisting XML file. The user can select items the gridview with checkboxes.
When the user hits the next button the xml file should be updating the showimage attribute with "0" or "1" from the checkbox value of the gridview.
the XML is wellformed and has a schema.
basically it looks like this
root
itemcode
filename showimage=
etc
etc
/root
root
itemcode
filename showimage=
etc
etc
/root
root
itemcode
filename showimage=
etc
etc
/root
I have come as far as :
For Each row As GridViewRow In GrdImagesSel.Rows
Dim cbSi As CheckBox = row.FindControl("chkShowImage")
Dim productID As String = Convert.ToString(GrdImagesSel.DataKeys(row.RowIndex).Value)
Dim SiNodelist As XmlNodeList
Dim SiNode As XmlNode
SiNodelist = xmldoc.SelectNodes("docroot/root")
For Each SiNode In SiNodelist
Dim ShowImg = SiNode.ChildNodes.Item(1).InnerText
If ShowImg = productID Then Parentnode.Attributes("ShowImage").Value = cbSi.Text
Next
Next
that doesn't work.
Can you help me out here?
Regards,
Bram
|
|
|
|
|
One, without formatting the xml properly it's difficult to see your structure.
Axiom70m wrote: that doesn't work.
Two, you have to give a little more information than this. What doesn't work? Are you getting exceptions? Is it just not functioning?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi, Thanks for you message. Here's the XML file:
<AfasGetConnector>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="AfasGetConnector">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="MNINT_Summary">
<xs:complexType>
<xs:sequence>
<xs:element name="Itemtype" type="xs:string" minOccurs="0" />
etc etc
<xs:element name="Afbeelding_in_Summary" type="xs:boolean" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<MNINT_Summary>
<Itemtype>2</Itemtype>
<Itemcode>0401023100</Itemcode>
<Omschrijving>Tales Legends - The Erzberg</Omschrijving>
<Gewichtseenheid_code>3</Gewichtseenheid_code>
<Bruto_gewicht>16</Bruto_gewicht>
<Bestandsnaam ShowImage="">ERZBERGAVRV.JPG</Bestandsnaam>
<Artikelcode>3988</Artikelcode>
<Nominale_waarde>€ 10</Nominale_waarde>
<Jaartal>2010</Jaartal>
<Metaal>Silver</Metaal>
<Kwaliteit>Proof</Kwaliteit>
<Fijnheid>.925</Fijnheid>
<Diameter>32</Diameter>
<Mintage>40000</Mintage>
<Prijs_5>24</Prijs_5>
<Prijs_25>22</Prijs_25>
<Prijs_50>20.75</Prijs_50>
<Prijs_100>19.9</Prijs_100>
<Sold_Out>false</Sold_Out>
<Land>Austria</Land>
<Logo_mint>AUT</Logo_mint>
<Gewijzigd_op>2010-03-10</Gewijzigd_op>
<Aangemaakt_op>2009-10-06</Aangemaakt_op>
<Uitgifte_datum>2010-04-14</Uitgifte_datum>
<Opnemen_in_Summary>false</Opnemen_in_Summary>
<Afbeelding_in_Summary>true</Afbeelding_in_Summary>
</MNINT_Summary>
<MNINT_Summary>
<Itemtype>2</Itemtype>
<Itemcode>0401023400</Itemcode>
<Omschrijving>Tales Legends - The Erzberg</Omschrijving>
<Gewichtseenheid_code>3</Gewichtseenheid_code>
<Bruto_gewicht>16</Bruto_gewicht>
<Bestandsnaam ShowImage="">ERZBERGAVRV.JPG</Bestandsnaam>
<Artikelcode>3984</Artikelcode>
<Nominale_waarde>€ 10</Nominale_waarde>
<Jaartal>2010</Jaartal>
<Metaal>Silver</Metaal>
<Kwaliteit>Unc</Kwaliteit>
<Fijnheid>.925</Fijnheid>
<Diameter>32</Diameter>
<Mintage>130000</Mintage>
<Prijs_5>12.5</Prijs_5>
<Prijs_25>11.75</Prijs_25>
<Prijs_50>11.25</Prijs_50>
<Prijs_100>11</Prijs_100>
<Sold_Out>false</Sold_Out>
<Land>Austria</Land>
<Logo_mint>AUT</Logo_mint>
<Gewijzigd_op>2010-03-10</Gewijzigd_op>
<Aangemaakt_op>2009-10-06</Aangemaakt_op>
<Uitgifte_datum>2010-04-14</Uitgifte_datum>
<Opnemen_in_Summary>false</Opnemen_in_Summary>
<Afbeelding_in_Summary>true</Afbeelding_in_Summary>
</MNINT_Summary>
<MNINT_Summary>
<Itemtype>2</Itemtype>
<Itemcode>0401024300</Itemcode>
<Omschrijving>Renewable Energy NIOB</Omschrijving>
<Gewichtseenheid_code>3</Gewichtseenheid_code>
<Bruto_gewicht>9.1</Bruto_gewicht>
<Bestandsnaam ShowImage="">25EErneuerbareEnergieAVRV.JPG</Bestandsnaam>
<Artikelcode>3983</Artikelcode>
<Nominale_waarde>25 €</Nominale_waarde>
<Jaartal>2010</Jaartal>
<Metaal>Silver</Metaal>
<Kwaliteit>B.U.</Kwaliteit>
<Fijnheid>.9</Fijnheid>
<Diameter>34</Diameter>
<Mintage>65000</Mintage>
<Prijs_5>44</Prijs_5>
<Prijs_25>42.25</Prijs_25>
<Prijs_50>40.5</Prijs_50>
<Prijs_100>39.5</Prijs_100>
<Sold_Out>false</Sold_Out>
<Land>Austria</Land>
<Logo_mint>AUT</Logo_mint>
<Gewijzigd_op>2010-02-03</Gewijzigd_op>
<Aangemaakt_op>2009-10-06</Aangemaakt_op>
<Uitgifte_datum>2010-03-10</Uitgifte_datum>
<Opnemen_in_Summary>false</Opnemen_in_Summary>
<Afbeelding_in_Summary>true</Afbeelding_in_Summary>
</MNINT_Summary>
</AfasGetConnector>
I've added an atribute ShowImage in this file. The value should be added based on the gridview's checkboxes.
I don't get errors, it happens that only the last attribute gets a value or none at all.
I get stuck with looping through the gridview checkboxes and the itemcodes in the xml to get the right checkbox value with the right attribute...
This is what I've done so far...
For Each row As GridViewRow In GrdImagesSel.Rows
Dim cbSi As CheckBox = row.FindControl("chkShowImage")
'add the Itemcode to the row index
Dim productID As String = Convert.ToString(GrdImagesSel.DataKe(row.RowIndex).Value)
There should be some code that matches the productID to the itemcode in the XMLfile and if it matches add the value of the checkbox...
Thanks
modified on Tuesday, April 27, 2010 2:03 PM
|
|
|
|
|
Based on this schema your XPath expression would be "AfasGetConnector/MNINT_Summary[Itemcode=productID]"
XmlNode node = doc.SelectSingleNode("AfasGetConnector/MNINT_Summary[Itemcode=productID]");
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Thanks for your input, I realy appriciate it.
I'm still not sure how to make this work... How do I set the checkbox value in the ShowImage attribute XML?
Now only the last ShowImage attribute in the X<l gets="" a="" value="" and="" the="" other="" ones="" stay="" empty:
<pre="">
For Each row As GridViewRow In GrdImagesSel.Rows
Dim cbSi As CheckBox = row.FindControl("chkShowImage")
Dim productID As String = Convert.ToString(GrdImagesSel.DataKeys(row.RowIndex).Value)
Dim SiNode As XmlNode
SiNode = xmldoc.SelectSingleNode("AfasGetConnector/MNINT_Summary[Itemcode=productID]")
For Each SiNode In xmldoc
Parentnode.Attributes("ShowImage").Value = ("1")
Next
Next
Thank for reading
modified on Wednesday, April 28, 2010 4:13 AM
|
|
|
|
|
Please stop what you are doing and read the documentation for XmlDocument and related objects.
You can not use for/each on SiNode. SelectSingleNode Care to guess how many nodes this will return?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
That was not the smartest thing to do. I am totally lost here and getting a bit obsessed with this.
I can't figure out how I should do this, i thought it would be easier this way. If you can give me any clue it would be very much appreciated. Thanks for your replies and time.
Regards,
Bram
|
|
|
|
|
Thanks for the help, i solved the problem
For Each row As GridViewRow In GrdImagesSel.Rows
Dim cbSi As CheckBox = row.FindControl("chkShowImage")
'Koppel Itemcode van de row aan productID en
If cbSi IsNot Nothing AndAlso cbSi.Checked Then
Dim productID As String = Convert.ToString(GrdImagesSel.DataKeys(row.RowIndex).Value)
Dim root As XmlNode = xmldoc.DocumentElement
Dim nodeList As XmlNodeList = root.SelectNodes("MNINT_Summary/Itemcode")
For Each productNode As XmlNode In nodeList
If productNode.FirstChild.InnerText = productID Then
Dim ShowImage As XmlElement = xmldoc.CreateElement("ShowImage")
productNode.AppendChild(ShowImage)
ShowImage.InnerText = "1"
End If
Next
Else
Dim productID As String = Convert.ToString(GrdImagesSel.DataKeys(row.RowIndex).Value)
Dim root As XmlNode = xmldoc.DocumentElement
Dim nodeList As XmlNodeList = root.SelectNodes("MNINT_Summary/Itemcode")
For Each productNode As XmlNode In nodeList
If productNode.FirstChild.InnerText = productID Then
Dim ShowImage As XmlElement = xmldoc.CreateElement("ShowImage")
productNode.AppendChild(ShowImage)
ShowImage.InnerText = "0"
End If
Next
End If
Next
|
|
|
|
|
Hi,
I hope I'm on the right forum.
My question is: how to create sitemap.xml file for your website? Is there any software? I see a lot of webmasters talking about how important is to have sitemap.xml.
Thanks!
|
|
|
|
|
|
|
Hi All,
I have some XML files which contains nodes word formatting nodes e.g..
w:pPr,w:r,w:t .
I want to see this XML file without word formatting.
Which tool or what setting i need to change to view this file without word formatting.
Thanks in Advance.
The secret of life is not enjoyment
but education through experience.
- Swami Vivekananda.
|
|
|
|
|
Hello Coders,
Im facing a problem building a C#.net code that will build me the following XML page:
<?xml version="1.0"?>
<chores>
<day title="some title">
<job a=".." b="text.." c="..text.." d="d..."/>
<job a=".." b="text.." c="..text.." d="d..."/>
<job a=".." b="text.." c="..text.." d="d..."/>
</day>
<day title="some title">
<job a=".." b="text.." c="..text.." d="d..."/>
<job a=".." b="text.." c="..text.." d="d..."/>
<job a=".." b="text.." c="..text.." d="d..."/>
</day>
<day title="some title">
<job a=".." b="text.." c="..text.." d="d..."/>
<job a=".." b="text.." c="..text.." d="d..."/>
<job a=".." b="text.." c="..text.." d="d..."/>
</day>
</chores>
I've tried hundreds of codes, nothing worked the way i need it. i will appreciate any help PLEASE.
What im trying to do is the following:
I have a page that has 4 textboxes, each one is supposed to save some value .. lets say a,b,c,d..
Another textbox is for the day attribute which is TITLE according to my example
I need to add whenever i need a DAY. with it's attribute. and "jobs" like that example.
whenever i need to make a new "DAY" i need it do be after the last one. i mean i need it to update the new <DAY> after the last one's
and all of that i need it to come before the each time i update the xml file</chores>
Please i'd really appreciate any help with this. im new to XML and im trying to make an XML management page for some project.If what i've said wasnt clear im ready to explain again. Please tell me what to do and how to do it, or if you have any samples for handling such an issue it will be great too
|
|
|
|
|
Can you show us a little of what you tried?
What you are trying to do is maintaining a kind of database.
On the assumption that you really want it as xml-file :
option 1 : Read your file as XmlDocument and add nodes as you add entries.
option 2 : Create a dedicated class model with serializing/deserializing.
Both methods have as disadvantage that everything get loaded in memory. To prevent that you might have to split your model in multiple files.
Google for XmlDocument and/or XSD utility.
If you need further clarification, just ask.
|
|
|
|
|
i've tried this code for example
XmlDocument XDoc = new XmlDocument();
XmlElement Xchores = XDoc.CreateElement("day");
XmlElement XElemRoot = XDoc.CreateElement("chores");
XElemRoot.AppendChild(Xchores);
Xchores.SetAttribute("label", "" + this.txtBoxCat.Text + "");
XDoc.AppendChild(XElemRoot);
XmlElement Xjob = XDoc.CreateElement("job");
while (this.Label5.Text == "1")
{
Xjob.SetAttribute("a", "" + this.txtBoxAbout.Text + "");
Xjob.SetAttribute("b", "" + this.txtBoxSize.Text + "");
Xjob.SetAttribute("c", "" + this.txtBoxPrice.Text + "");
Xjob.SetAttribute("d", "" + this.txtBoxAmount.Text + "");
Xchores.AppendChild(Xjob);
XDoc.Save("chores2.xml");
}
and ive tried it by making a dataset of the elements
DataSet ds = new DataSet();
ds.ReadXml("chores2.xml"); DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("a"));
dt.Columns.Add(new DataColumn("b"));
dt.Columns.Add(new DataColumn("c"));
dt.Columns.Add(new DataColumn("d"));
DataRow dr = dt.NewRow();
dr[0] = ""+this.txtBoxSize.Text+"";
dr[1] = "" + this.txtBoxAbout.Text + "";
dr[2] = "" + this.txtBoxAmount.Text + "";
dr[3] = "" + this.txtBoxSize.Text + "";
dt.Rows.Add(dr);
ds.Tables.Add(dt);
ds.Relations.Add(new
DataRelation("myrel", ds.Tables[1].Columns[0], ds.Tables[0].Columns[0]));
ds.Relations[0].Nested = true;
ds.WriteXml("chores2.xml");
and i've tried it by getting the values from an access database and save them as an XML file
also that didnt help approaching my goal
OleDbConnection con = new OleDbConnection();
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb";
OleDbDataAdapter da = new OleDbDataAdapter("Select * from job1", con);
DataSet ds = new DataSet("chores");
DataTable xjob = new DataTable();
xjob = xjob.Tables["job"];
da.Fill(ds, "day");
ds.WriteXml("chores2.xml");
*/
string jobName = this.TextBox2.Text;
OleDbConnection con = new OleDbConnection();
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb";
OleDbDataAdapter da = new OleDbDataAdapter("Select * from "+jobName+"", con);
DataSet ds = new DataSet("chores");
while (this.Label5.Text == "1")
{
da.Fill(ds, "job");
DataTable dt = new DataTable("job");
dt = ds.Tables["job"];
foreach (DataColumn dc in dt.Columns)
{
dc.ColumnMapping = MappingType.Attribute;
}
}
ds.WriteXml("chores2.xml");
and i tried the XMLDocument, also didnt work exactly how i want it
i would be more than happy if you can explain me what do you mean by
:
option 2 : Create a dedicated class model with serializing/deserializing
|
|
|
|
|
Your approach with XmlDocument in itself works, I tried your code.
What you need to to there is first checking if the file exists and if so xDoc.Load(<file>); .
FileInfo fi1 = new System.IO.FileInfo(@"c:\temp\chores2.xml");
if (!fi1.Exists)
{
XDoc.Load(@"c:\temp\chores2.xml")
}
else
{
XmlElement XElemRoot = XDoc.CreateElement("chores");
XDoc.AppendChild(XElemRoot);
}
To add a job to a particular day you need to find the node with the right title :
XDoc.SelectSingleNode("descendant::day[@title='YourTitle']");
You can now add your jobs to it.
About option 2, MS has a utility called XSD. On my PC it's in :
C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\xsd.exe
With your xml you can generate an xsd, and with the xsd you can generate a .cs file.
It has all the classes and attributes you need. You can and should edit it to suit your needs.
The only thing left to do is write a serializer and a deserializer.
The code would look something like this (I removed all attributes)
public partial class chores {
private choresDay[] itemsField;
public choresDay[] Items {
get {
return this.itemsField;
}
set {
this.itemsField = value;
}
}
}
public partial class choresDay {
private choresDayJob[] jobField;
private string titleField;
public choresDayJob[] job {
get {
return this.jobField;
}
set {
this.jobField = value;
}
}
public string title {
get {
return this.titleField;
}
set {
this.titleField = value;
}
}
}
public partial class choresDayJob {
private string aField;
private string bField;
private string cField;
private string dField;
public string a {
get {
return this.aField;
}
set {
this.aField = value;
}
}
public string b {
get {
return this.bField;
}
set {
this.bField = value;
}
}
public string c {
get {
return this.cField;
}
set {
this.cField = value;
}
}
public string d {
get {
return this.dField;
}
set {
this.dField = value;
}
}
}
You would use it :
chores chores = new chores();
chores.Items = new choresDay[];
chores.Items[0] = new choresDay;;
chores.Items[0].job = new choresDayJob[];
chores.Items[0].job[0] = new choresDayJob();
chores.Items[0].job[0].a = this.a;
chores.Items[0].job[0].b = this.b;
Good luck!
|
|
|
|
|
Hi Estys,
First of all thank you a lot for your help and time, i really appreciate that.
Second, i think im gonna take option #1 lol.
Anyway, this is the code i've made for now, im not sure about it but i'd really appreciate more help.
protected void Button1_Click(object sender, EventArgs e)
{
XmlDocument XDoc = new XmlDocument();
FileInfo fi1 = new System.IO.FileInfo("chores2.xml");
if (!fi1.Exists)
{
XDoc.Load("chores2.xml");
}
else
{
XmlNode root = XDoc.DocumentElement;
XDoc.SelectSingleNode("descendant::day[@title='"+this.dropdwnlst.selectedvalue+"']");
XmlElement Xjob = XDoc.CreateElement("job");
Xjob.SetAttribute("a", "" + this.txtBoxProduct.Text + "");
Xjob.SetAttribute("b", "" + this.txtBoxSize.Text + "");
Xjob.SetAttribute("c", "" + this.txtBoxPrice.Text + "");
Xjob.SetAttribute("d", "" + this.txtBoxAmount.Text + "")
XDoc.Save("chores2.xml");
}
}
this is what im thinking about, i have 4 text boxes for the job attributes. with another DropDownList that through it i can choose what kind of a "DAY" according to the title i want to play with and add "jobs".
So, this cute line
XDoc.SelectSingleNode("descendant::day[@title='"+this.dropdwnlst.selectedvalue+"']");
is really great, but how i can control my selected node and enter the correct attributes
Xjob.SetAttribute("a", "" + this.txtBoxProduct.Text + "");
Xjob.SetAttribute("b", "" + this.txtBoxSize.Text + "");
Xjob.SetAttribute("c", "" + this.txtBoxPrice.Text + "");
Xjob.SetAttribute("d", "" + this.txtBoxAmount.Text + "")
to it?
Thanks again for your help.
|
|
|
|
|
Your form code should look like this :
public partial class choreForm : Form
{
XmlDocument xDoc = new XmlDocument();
public choreForm()
{
InitializeComponent();
}
private void choreForm_Load(object sender, EventArgs e)
{
FileInfo fi1 = new FileInfo(GetFileName());
if (fi1.Exists)
{
xDoc.Load(GetFileName());
}
else
{
xDoc.AppendChild(xDoc.CreateElement("chores"));
}
}
private void button1_Click(object sender, EventArgs e)
{
XmlElement xDay = xDoc.SelectSingleNode("descendant::day[@title='" + this.dropdwnlst.selectedvalue + "']") as XmlElement;
if (xDay == null)
{
xDay = xDoc.CreateElement("day");
xDay.SetAttribute("title", this.dropdwnlst.selectedvalue);
xDoc.FirstChild.AppendChild(xDay);
}
XmlElement xJob = xDoc.CreateElement("job");
xJob.SetAttribute("a", this.txtBoxProduct.Text);
xJob.SetAttribute("b", this.txtBoxSize.Text);
xJob.SetAttribute("c", this.txtBoxPrice.Text);
xJob.SetAttribute("d", this.txtBoxAmount.Text);
xDay.AppendChild(xJob);
}
private void choreForm_FormClosing(object sender, FormClosingEventArgs e)
{
xDoc.Save(GetFileName());
}
private string GetFileName()
{
return @"c:\temp\chores2.xml";
}
}
gimme 5 if you like this!
|
|
|
|
|