|
I'm pretty new to programming XML on .NET. I'm looking for best practices on constructing an XML document.
Do I have anything to gain by building an XML document with a StringBuilder and then converting it to an XmlDocument? Should I just create the document using the proper objects as I go along? Any other tips?
Thanks,
-- modified at 1:36 Wednesday 20th September, 2006
Edit: Upon further investigation, it looks like XmlTextWriter is what I'm after.
|
|
|
|
|
string PI= "type='text/xsl' href='Whatever.xsl'";
XmlTextWriter myXmlTextWriter = new XmlTextWriter("PATH.xml", null);
myXmlTextWriter.Formatting = Formatting.Indented;
myXmlTextWriter.WriteStartDocument();
myXmlTextWriter.WriteProcessingInstruction("xml-stylesheet", PI);
//Open tag.
myXmlTextWriter.WriteStartElement("TagName");
//Open Tag with Attribute.
myXmlTextWriter.WriteStartElement("TagName2",null);
myXmlTextWriter.WriteAttributeString("key", Convert.ToString(counter));
//StartTagAndEndTagWithValue
myXmlTextWriter.WriteElementString("TagName3","What You Want Between Tags");
//Close Tag. This One Closes the "TagName2".
myXmlTextWriter.WriteEndElement();
//Close Tag. This One Closes the "TagName".
myXmlTextWriter.WriteEndElement();
//Write the XML to file(Look at "PATH.xml" part at the top)and close the myXmlTextWriter
myXmlTextWriter.Flush();
myXmlTextWriter.Close();
Hope that it is of some help...
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
|
Hello,
Could someone please refer me to an article, link, website to how this works. Or even better, explain to me the process from start to finsih. I just dont understand how this works completely.
Thanks
Steve-o H.
There are 10 kinds of people in this world... Those who understand binary and those who dont.
|
|
|
|
|
|
We have been bitten by severe memory leaks in our project.
While having a dry run of one of the components code. I came across the following. This looks like a sure shot memory leak to me. Because of the fact that we are not doing a VariantClear().
Please confirm.
<<
try
{
IXMLDOMSchemaCollection2Ptr m_pSchemaCache;
hr=m_pSchemaCache.CreateInstance(__uuidof(MSXML2::XMLSchemaCache60));
if (SUCCEEDED(hr))
{
hr=m_pSchemaCache->add(szNameSpace_in, szSchemaFilePath_in);
if (SUCCEEDED(hr))
{
VARIANT varValue;
varValue.vt = VT_DISPATCH;
varValue.pdispVal = m_pSchemaCache.GetInterfacePtr();
m_pSchemaCache.AddRef();
m_pDOMDoc->PutRefschemas(varValue);
}
else
{
this->m_errorCode=ERR_XML_DOC_SCHEMA_ADDITION_FAILED;
return FALSE;
}
}
else
{
this->m_errorCode=ERR_XML_DOC_SCHEMA_INSTANCE_CREATION_FAILED;
}
}
>>
Rajdeep
|
|
|
|
|
how can i pass xml nodes from a web service to a client.. as i m doin it in the normal way the way we pass strings but its giving a parser error and soap exception that value cannot be null
it gives an error at this line of code at the client:
xmlnode n=service.getnode();
bia ali
|
|
|
|
|
(string-length(normalize-space($Curnode/@*[position()=7])) != 0)*($MsgLength + 5)
What will the above expression return if normalize-space($Curnode/@*[position()=7]) returns "0020100101".
What will (string-length("0020100101")!=0) return true,1,or stringlength???
|
|
|
|
|
HI all
I have given a problem set in which i need to parse an xml document of size near about 1GB. In which the it should able to Parse/Load/Search the xml document in efficiently .
Now please anyone help me how to go for this means which are possible way and which is better PLease help me
|
|
|
|
|
|
Yes i have downloaded that project but its not related my query but i get the idea to read the fiel in chunk
|
|
|
|
|
Hi All,
I have a XML string with me in the format
<row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SEQNO>6</SEQNO>
<B_CO_CD>H</B_CO_CD>
<B_AREA_CD>K</B_AREA_CD>
</row>
the XML tags are taken in an actual string variable and then I need to find a particular tag and get its value to actually set that value in a dataset column that corresponds to this tag.
How can I do this ??
Pls guide me.. I need to give demo on this..Pls Pls
Omkar
|
|
|
|
|
Hi Omkar,
find below the code to get value in a particular tag.
System.Data.DataSet ds=new DataSet();
ds.ReadXml("D:\\MY_WORK\\ssis projects\\Executessis\\WindowsApplication1\\XMLFile1.xml");//here set your xml file path
int i=ds.Tables[0].Columns["SEQNO"].Ordinal;//getting the position of the column/tag
string s=ds.Tables[0].Rows[0].ItemArray.GetValue(i).ToString();//getting the actual vlaue inside the tag
Tell me if it will not work...
Regards,
Saurabh Maheshwari
Nucleus Software ,Noida
|
|
|
|
|
Hi,
I have a directory containing loads of xml files that change regularly. To generate a list of all the files in the directory i use this code:
Sub Page_Load(sender as Object, e as EventArgs)<br />
If Not Page.IsPostBack then<br />
Dim dirInfo as New DirectoryInfo(Server.MapPath(""))<br />
repeater.DataSource = dirInfo.GetFiles("*.xml")<br />
repeater.DataBind()<br />
End If<br />
End Sub
I then display this information in a asp repeater. Currently it lists the filename and size and when the document was last edited.
I wish to extend this concept to allow me to display the 'title' element of each xml file alongside the filename in my asp repeater. I know how to extract the 'title' from a static list of xml files by explicity binding to each one, but i dont know how to do this 'on the fly' with the xml files in my generated list. I hope that made relative sense to somebody.
Thanks alot.
Colm.
|
|
|
|
|
"<xsl:with-param name="Curnode" select="//RealTimeData/*[position()=count(//RealTimeData/MasterData)]" />"
Kindly explain the select clause ...particularly what does the * imply here
Please elaborate on the result of each step....
-- modified at 5:44 Thursday 14th September, 2006
|
|
|
|
|
* means zero or more occurences
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
I have, for example, a variable $title accepting value (a string with value "title") from a text box .
Then I want to use this string to make reference to an element when I try to use a template that accepts a parameter as a node set.
<xsl:call-template name="show-items">
<xsl:with-param name="text" select="$title"/>
</xsl:call-template>
My xml is like this
<book>
<lang>english</lang>
<title>XML Basics</title>
<content>
......
</content>
</book>
but it does not work. The title accepted in the template "show-items" is not "XML Basics" but "title".
Please help!!!!
|
|
|
|
|
What you want to do is pass parameter "text" in "show-items" template with value "XML Basics" in it???
Try
<xsl:with-param name="text" select="/book/title/text()"/>
|
|
|
|
|
I want to use like
<xsl:with-param name="title" select="/book/$title">
but it doesn't work. It is said that a node set is needed, while the value of $title is 'title' (a string) not the title element, the "//book/title" one, the child node element of the book.
All I have now is a string with the value is the name of that element, and I want to use this name, translate it into a real element and then use that element.
Can I do that?
|
|
|
|
|
how can i pass xml nodes from a web service to a client.. as i m doin it in the normal way the way we pass string but its giving a parser error and soap exception
rabia
|
|
|
|
|
I help a small structure below
<jokes>
<joke>
<cat>poem</cat>
<title>ABC</title>
<content>
...
</content>
</joke>
<joke>
<title>123</title>
<content>
...
</content>
</joke>
</jokes>
As you can see, the values for <cat> is "poem" and "normal", for example. But I would like to make it like, when the <cat>poem</cat> appears, it means, the joke is in poem. But if the <joke> does not have <cat> or it has a empty pair <cat></cat>, the type of that joke is considered to be "normal".
How can I check to see if a tag is empty or not present?
|
|
|
|
|
You can test for the presence of a tag with XPath by just writing the tag name: //joke/cat This selects all <joke> tags that have a child <cat> tag. This selects all <cat> tags that are children of a <joke> tag. To test the actual contents of the <cat> you'll need other XPath functions (I just know basic XPath so I don't know the functions by heart, check out the docs)
|
|
|
|
|
Michael Dunn wrote: You can test for the presence of a tag with XPath by just writing the tag name: //joke/cat This selects all <joke> tags that have a child <cat> tag.
No, that would select the "cat" elements not the "joke" elements.
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real" Score: 1.0 in the Soap Box
led mike
|
|
|
|
|
I was thinking the right thing, but explained it backwards.
|
|
|
|