Escolar Documentos
Profissional Documentos
Cultura Documentos
Windows Programming
XML Support
Department of Computer Science and Engineering
University of South Carolina
Columbia, SC 29208
Why XML?
XML stands for eXtensible Markup Language.
XML is an extension of HTML; it is designed to express the structure
of data and information about how to render the data.
Some organizations are embarked on defining standards that use XML
to express the semantics of their domains (healthcare, automotive,
security and the military).
WHY XML? Because:
XML
XML documents contain two parts, called the header and the content.
?xml
<?xml version="1.0"?>
<?xml-stylesheet href="XSL\DotNet.html.xsl" type="text/xsl"?>
<?xml-stylesheet href="XSL\DotNet.wml.xsl" type="text/xsl"
media="wap"?>
<?cocoon-process type="xslt"?>
Declarations
<!DOCTYPE DotNetXML:Book SYSTEM "DTD\DotNetXML.dtd">
<!NOTATION PNG SYSTEM “program.exe”>
<!ATTLIST . . . >
<memo> </memo>
But this only makes sense when creating attributes. The preferred
way is:
<memo />
<?xml version="1.0"?>
<win:Guitars
xmlns:win="http://www.wintellect.com/classic-guitars"
xmlns:gibson="http://www.gibson.com/finishes"
xmlns:fender="http://www.fender.com/finishes">
<win:Guitar>
<win:Make>Gibson</win:Make>
<win:Model>SG</win:Model>
<win:Year>1977</win:Year>
<gibson:Color>Tobacco Sunburst</gibson:Color>
<win:Neck>Rosewood</win:Neck>
</win:Guitar>
<win:Guitar>
<win:Make>Fender</win:Make>
<win:Model>Stratocaster</win:Model>
<win:Year>1990</win:Year>
<fender:Color>Black</fender:Color>
<win:Neck>Maple</win:Neck>
</win:Guitar>
</win:Guitars>
<?xml version="1.0"?>
<win:Guitars Default Name Space
xmlns="http://www.wintellect.com/classic-guitars"
xmlns:gibson="http://www.gibson.com/finishes"
xmlns:fender="http://www.fender.com/finishes">
<Guitar>
<Make>Gibson</Make>
<Model>SG</Model>
<Year>1977</Year>
<gibson:Color>Tobacco Sunburst</gibson:Color>
<Neck>Rosewood</Neck>
</Guitar>
<Guitar>
<Make>Fender</Make>
<Model>Stratocaster</Model>
<Year>1990</Year>
<fender:Color>Black</fender:Color>
<Neck>Maple</Neck>
</Guitar>
</Guitars>
hr = pDoc
pDoc->getElementsByTagName (tag, &pNodeList);
using System;
using System.Xml;
class MyApp
{
static void Main ()
{
XmlDocument doc = new XmlDocument ();
doc.Load ("Guitars.xml");
XmlNodeList nodes = doc.GetElementsByTagName
GetElementsByTagName ("Guitar");
foreach (XmlNode
XmlNode node in nodes) {
Console.WriteLine ("{0} {1}", node["Make"].InnerText,
node["Model"].InnerText);
}
}
}
if (node.HasChildNodes) {
XmlNodeList children = node.ChildNodes;
foreach (XmlNode child in children)
OutputNode (child);
}
} The items in red are defined in
the Xml Name Space
if (node.HasChildNodes) {
foreach (XmlNode child in node.ChildNodes)
OutputNode (child);
} HasChildNode and ChildNodes
}
writer.WriteStartDocument ();
writer.WriteStartElement ("Guitars");
writer.WriteStartElement ("Guitar");
writer.WriteAttributeString ("Image", "MySG.jpeg");
writer.WriteElementString ("Make", "Gibson");
writer.WriteElementString ("Model", "SG");
writer.WriteElementString ("Year", "1977");
writer.WriteElementString ("Color", "Tobacco <?xml
Sunburst");
version="1.0" encoding="utf-16"?>
writer.WriteElementString ("Neck", "Rosewood");
<Guitars>
writer.WriteEndElement (); <Guitar Image="MySG.jpeg">
writer.WriteEndElement (); <Make>Gibson</Make>
} <Model>SG</Model>
finally { <Year>1977</Year>
if (writer != null) <Color>Tobacco Sunburst</Color>
writer.Close (); <Neck>Rosewood</Neck>
} </Guitar>
</Guitars>
The code in
<?xml-
<?xml-stylesheet type="text/
type="text/xsl
xsl"
" href
href="
="Guitars.xsl
Guitars.xsl"?>
"?>
Note that the key to get this done is to have a good understanding of .XSL
specifics.