Reading in all of an XML Doc
Posted: Thu Dec 17, 2009 10:27 am
I'm trying to read in an XML doc completely, not just the contents of the nodes. I'm able to do it with [ahem] ASP but i can't figure it out in PHP. I've played around with DOMDocument and fgets but the best i've got is just the contents of the nodes - not the complete xml.
The XML file has elements in it that i search for and replace from a database. I then output the final updated XML. The reasoning for this is speed [in terms of on going dev] and simplicity [i'm not great in PHP].
If anyone can help or point me in the right direction that would be great.
For what it's worth here's the ASP that i've used:
The XML file has elements in it that i search for and replace from a database. I then output the final updated XML. The reasoning for this is speed [in terms of on going dev] and simplicity [i'm not great in PHP].
If anyone can help or point me in the right direction that would be great.
For what it's worth here's the ASP that i've used:
Code: Select all
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/xml";
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
//write XML here
StreamReader streamReader = new StreamReader("C:\\Inetpub\\wwwroot\\Admin\\output\\content.xml");
string strXML = streamReader.ReadToEnd();
streamReader.Close();
//get translation data for current language
string strFriendlyName;
string strTranslation;
SqlConnection SqlConn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand SqlComm = new SqlCommand("spGetTranslations", SqlConn);
SqlComm.CommandType = CommandType.StoredProcedure;
SqlComm.Parameters.Add(new SqlParameter("@LauguageID", globalFunctions.intCount));
SqlConn.Open();
SqlDataReader SqlDataReader = SqlComm.ExecuteReader();
//replace placeholders with translation data
if (SqlDataReader.HasRows)
{
while (SqlDataReader.Read())
{
strFriendlyName = SqlDataReader["FriendlyName"].ToString();
strTranslation = SqlDataReader["Translation"].ToString();
strXML = strXML.Replace("**" + strFriendlyName + "**", strTranslation);
}
}
SqlConn.Close();
SqlComm.Parameters.Clear();
SqlDataReader.Close();
context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(0));
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Write(strXML);
}