|
Sounds like a job for XSLT. The .NET Framework provides classes for this in the System.Xml.Xsl namespace. If you want to get to know XSLT in general, take a look at this site: XSLT Tutorial[^]
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi all,
I need to be parse the XML file. So, please send any light weight XML parser library in Visual studio 2005.
Already I have been tried one XML parser. But there is some memory problem would arrive whenever run my application. The name of that one is "Apache's Xerces C++ Parser" by Fengjun Lv.
Thanks in advance
|
|
|
|
|
You could use XmlDocument or Xmlreader ; both contained in the System.Xml namespace of the .NET Framework Class Library.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
How I can send XML packet over network? and How I can received that packet on server..
|
|
|
|
|
The XmlDocument.Load and XmlDocument.Save methods have overloads that take a Stream object, so you should be able to pass in a NetworkStream. Alternatively, you could use the XmlTextReader and XmlTextWriter . Both have a constructor that also takes a Stream object.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
I have an xml document where certain elements have attributes with generic names and values. Like this:
Data.xml
<DATA sport="football">
<ROW firstname="John" lastname="Doe" s1="130" s2="3" s3="43.3" />
</DATA>
And I have metadata which describes the data. The metadata is not in XML format so if there is an alternative to what I'm attempting to do, please let me know. But what I am trying to do is put the metadata in the following format:
Meta.xml
<METADATA>
<FIELDS sport="football">
<FIELD field="s1" name="RushingYards" />
<FIELD field="s2" name="RushingAttempts" />
<FIELD field="s3" name="RushingYardsPerCarry" />
....... blah, blah, blah .....
</FIELDS>
</METADATA>
I want to create a stylesheet that can use "Meta.xml" to transform Data.xml into this:
<DATA sport="football">
<ROW firstname="John" lastname="Doe" RushingYards="130" RushingAttempts="3" RushingYardsPerCarry="43.3" />
</DATA>
The part I don't know how to do is to tell the XslTransform object to transform Data.xml and use Meta.xml as variable input. Can I simply pass Meta.xml in as a parameter to XslTransform?
|
|
|
|
|
I solved it myself - I ended up using an XmlReader to read Data.xml. Then instead of using Meta.xml I just used the metadata in it's original tabular format. As the process reads Data.xml it looks for ROW elements and checks the names of the attributes against the metadata. While reading Data.xml I create an XmlTextWriter to correspond to the XmlReader. If I need to change the attribute name or value I substitute, otherwise I just output the data from the XmlReader.
|
|
|
|
|
I've made a C# application which modifies XML files, but sometimes the resulting file contains the BOM header (EFBBBF hex as first three characters) which the systems which need to take the updated file as input do not accept.
I know I could probably open the file after modification and remove the characters, but that seems like a hack.
Is there a way to specify the encoding to be something different (or any other way) so that it doesn't create this? The code I'm currently using to open the file is:
try<br />
{<br />
xmlDoc = new XmlDocument();<br />
xmlDoc.Load(Filename);<br />
<br />
xpathNav = xmlDoc.CreateNavigator();<br />
return true;<br />
...
|
|
|
|
|
I think it is more interesting to see the code that saves the XML files.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
The code I use to save the file out is very simple, the iterator is an XPathNodeIterator and the doc is an XmlDocument
<br />
xpathIter.Current.SetValue(NewValue);<br />
xmlDoc.Save(Filename);<br />
|
|
|
|
|
I assumed that but just wanted to make sure. I never came across a property or similar that lets you adjust the usage of a BOM header and after a quick glance at MSDN I also did not find one. In your original post you said that the BOM header is only sometimes put in front of the XML markup. Are you able to narrow this down the some concrete conditions under which this happens?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
The input XML files are configuration files from hardware units, but the format differs slightly depending on the version of hardware. I have only just come up against this BOM header insertion, but it seems like it could be a certain age (not sure whether it's newer or older at the moment) hardware gives an XML file which ends up being edited in my application and the BOM header added.
The file does have the UTF-8 ?xml tag at the top which I am assuming is causing the BOM header to be added by the .NET parser, but that's the bit that causes the hardware unit to not accept the new config file.
|
|
|
|
|
Ok, in case you're using Framework 2.0, there may be a way to get around your problem. The XmlDocument.Save method has an overload that takes an XmlWriter object. The XmlWriter class has a overload of the static Create method that takes a filename and a XmlWriterSettings instance (class is new in 2.0). This class exposes a Encoding property that allows to specify the text encoding to be used. Finally there is the UTF8Encoding class that has a constructor taking a boolean that specifies whether the byte order marked is provided or not.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Fantastic, that sounds like what I need. I'm using 2.0, so I'll take a look at writing out in that way.
Thanks a lot
|
|
|
|
|
That seemed to do the trick, but using this method the XML file is saved without line breaks at all. I've tried changing the various options of XmlWriterSettings but can't work out how to make sure the file is formatted properly. When I was just using xmlDoc.Save it was laying the file out correctly but adding the BOM, now it's saving the file in the right encoding (I chose ASCII rather than UTF-8 as that's what the files I'm editing are in) but without the formatting (which again is causing errors with the hardware units).
|
|
|
|
|
I'm sorry to hear it does not work properly. Since I have no pratical experience with customizing the writing of XMl files (output generated by XmlDocument.Save was always sufficient for my needs), I cannot really help you here. The best thing I can suggest is playing around with the properties of the XmlWriterSettings class regarding new lines (obviously you already done this), check whether this only happens if you use the ASCIIEncoding class or also with other encodings and maybe use the same XmlWriterSettings for reading too.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
I finally worked it out... the XmlWriterSettings.Indent setting not only indents, but also adds the line breaks.
|
|
|
|
|
Duncan Sample wrote: I finally worked it out...
Congratulation
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi..
I need to create aspx page dynamically using xml and xslt? Could anyone please help me in creating an Aspx page using xml and xslt.
Thanks & Regards,
Venkat
|
|
|
|
|
What is it exactly that you need help with?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
I need to create new aspx page with the help of xml and xslt? The aspx page has to be created hrough xml and xslt
Thanks & Regards,
Venkat
|
|
|
|
|
You already said that. Simply repeating your question does not bring you any closer to getting a useful answer.
So I rephrase the question a bit. What should be contained in the XML file and what should the transformation with XSLT do? Did you already read something about XSLT? If not the following site would be a good starting point http://www.w3schools.com/xsl/.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
What are you trying to create from xml file? Final HTML markup, or "aspx page" with user controls like <asp:TextBox> etc?
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
I want to have an array of finite numbers/strings in the xml and validate it using the XSD file, can this be done
i know i could concatenate the array pass as comma seperated string or something but is there a better more standard way
thanks for your help
If you think you can than you can, if you think you can't you are right.
|
|
|
|
|
I'd suggest using a structure like this:
<complexType name="numbersArray">
<sequence>
<element name="item" type="xsd:int" minOccurs="0" maxOccurs="unbounded" />
</sequence>
</complexType>
A conforming XML file would look like this:
<numbersArray>
<item>1</item>
<item>5</item>
</numbersArray>
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cookwww.troschuetz.de
|
|
|
|