|
Hi, I asked a Q in C# forum, but i also trying here.
please help me with this Q
many thanks
|
|
|
|
|
Hi.
How can i save a word document to xml format for parsing later with xslt.
I noticed that word 2007-2010 document are constructed with the openxml format so i can use openxml tools to save it.
But word 2000-2003 seems to be in binary format.
Is there a tool that i can use for this mission?
Thanks
|
|
|
|
|
don't post same question in more than one forum.
It create cross post. be aware from it.
|
|
|
|
|
How do I include PHP codes in an XML file?
I have a FLASH Gallery that i want to alter the names of the photo's
but i can't do that because i don't know how to include the PHP in the XML file ,, can you help me ?
|
|
|
|
|
We need more details in order to answer this.
Why do you want to embed PHP in the XML? How is the XML being used? This sounds potentially dangerous.
|
|
|
|
|
how I can create multiple XML files from a single XML file using xsltproc?
|
|
|
|
|
If you are using XSL 2, you can use xsl:result-document to target multiple output documents.
|
|
|
|
|
I must use XSLTProc
it does not support XSLT 2.0
|
|
|
|
|
The only way I can see to do this with this tool then is to have multiple XSLT files and run them in sequence. It's not pretty, but XSLT 1 was not designed for a 1-in to many-out scenario.
|
|
|
|
|
|
You are welcome. I hope we have helped.
|
|
|
|
|
Good afternoon.
I have the following XML file structure:
<?xml version="1.0" ?>
- <WEB_SITE>
- <RECORD>
<Name>Homepage</Name>
<Address>http:
</RECORD>
</WEB_SITE>
I would like to derive the URL from the XML file if the name is Homepage.
I have this so far:
string strtmpName = string.Empty;
string strtmpAddress = string.Empty;
XmlTextReader reader = null;
XDocument xmlDoc = new XDocument();
reader = new XmlTextReader(cv.StrIndivPath1 + strLANID + cv.StrIndivPath2 + "Website.xml");
xmlDoc = XDocument.Load(reader);
reader.Close();
XElement Results = XElement.Parse(xmlDoc.ToString());
foreach (XElement xe in Results.Elements("RECORD").Descendants())
{
switch (xe.Name.ToString())
{
case "Name":
if (xe.Value.ToLower() == "homepage")
{
strtmpAddress = Results.Elements("RECORD").Descendants("Address").ToString();
MessageBox.Show(strtmpAddress);
}
break;
default:
break;
}
}
Any suggestions? Thank you, WHEELS
|
|
|
|
|
XPath can be used. Here is how it works:
String myXPath="/WEB_SITE/RECORD[Name='Homepage']/Address";
XmlNodeList myNodeList=xmlDoc.SelectNodes(myXPath);
XmlNode myXmlNode;
foreach (myXmlNode in xmlNodeList)
{
MessageBox.Show(myXmlNode.Value);
}
Cheers!
|
|
|
|
|
I am getting a Type and identifier are both required in a forach statement.
|
|
|
|
|
well you have to add this :
using System.Xml.Xpath;
so that it can identify the XPath.
|
|
|
|
|
Excellent. That does the trick. Thank you.
|
|
|
|
|
|
In order to use SelectNodes to select nodes and attributes that have a namespace prefix, you need an XmlNamespaceManager that knows about the namespace and prefix. Unfortunately, I haven't found a way to access a pre-populated XmlNamespaceManager or to automagically populate one from an XmlDocument.
According to the documentation, XmlReaders use XmlNamespaceManagers, so after I load a document with an XmlReader I should be able to copy the XmlReader's XmlNamespaceManager -- but it shows null (and requires Reflection). I should be able to pass an XmlNamespaceManager to an XmlReader and the XmlReader should use it -- but it still shows null.
I've gone through a bunch of documentation and searching articles here and elsewhere hasn't yielded a silver bullet. They all show code calling AddNamespace to add specific namespaces -- I need it to be dynamic.
So I'm trying to roll my own. At this point, I'm loading the document with an XmlReader and then trying to query any attributes in the xmlns namespace, I should then be able to populate an XmlNamespaceManager with AddNamespace.
The code, as I have it now (I've tried several variations of the XPath) is:
System.Xml.XmlNamespaceManager result =
new System.Xml.XmlNamespaceManager ( Document.NameTable ) ;
System.Xml.XmlNodeList nodes = Document.DocumentElement.SelectNodes ( "//@xmlns:*" , result ) ;
This should yield all the attributes in the xmlns namespace (and the document contains one), but the list comes up empty.
0) Can anyone provide me with an XPath that will do what I want?
1) Does anyone know how to get a pre-populated XmlNamespaceManager from an XmlReader or an XmlDocument?
|
|
|
|
|
I used this:
if (namespace_found)
{
nsmgr = gcnew XmlNamespaceManager (doc->NameTable);
nsmgr->AddNamespace(L"ie", DocNamespace);
}
namespace_found is set to true when a namespace and schema are present on the XML file.
I couldnt add a schema to the XML file at run time.
GER
Ger
|
|
|
|
|
In order to at least have something that works, I now have:
public static System.Xml.XmlNamespaceManager
GetNamespaceManager
(
System.Xml.XmlDocument Document
)
{
System.Xml.XmlNamespaceManager result =
new System.Xml.XmlNamespaceManager ( Document.NameTable ) ;
System.Xml.XmlNodeList nodes = Document.DocumentElement.SelectNodes ( "//*" , result ) ;
foreach
(
System.Xml.XmlNode nod
in
nodes
)
{
foreach ( System.Xml.XmlAttribute att in nod.Attributes )
{
if ( att.Prefix == "xmlns" )
{
result.AddNamespace ( att.LocalName , att.Value ) ;
}
}
}
return ( result ) ;
}
Which gets the job done, and I suppose that's what the framework would be doing anyway so it shouldn't be too much slower. But, if the XmlReader builds one anyway, I sure wish I could access it and not have to build my own.
|
|
|
|
|
There's a Scott Hanselman post here[^] that talks about using an XPathNavigator to get namespaces once it has a currentNode for scope. So this kind of thing works:
XmlNamespaceManager nsmgr = new XmlNamespaceManager( Document.NameTable );
XPathNavigator nav = Document.CreateNavigator();
nav.MoveToFollowing( XPathNodeType.Element );
foreach (var ns in nav.GetNamespacesInScope( XmlNamespaceScope.ExcludeXml ))
{
nsmgr.AddNamespace( ns.Key, ns.Value );
}
As you say, the framework may be doing the same work in each case.
|
|
|
|
|
Hmmm... interesting, thanks, I'll have to take a deeper look. So far I've just looked to see whether or not I can access a NamespaceManager within that, but I didn't see one.
|
|
|
|
|
hello guys,
I am reading xml file and showing in grid in c# but now i want to read specific record(node) of that xml file like where clouse in sqlserver
Example
<Root>
<Data id="1" Name="aaa" Phone="852963" Gender="Male" />
<Data id="2" Name="bbb" Phone="123456789" Gender="Female" />
<Data id="3" Name="ccc" Phone="987654" Gender="Male" />
<Data id="3" Name="ddd" Phone="7676767" Gender="Male" />
</Root>
i need to read the first(TOP)id record and who's Gender="male".
how to do this
Regards
Shafiq
|
|
|
|
|
Try Bipin Joshi's book "Beginning XML with C# 2008" by Apress. I think thats there.
~GER
Ger
|
|
|
|
|