Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
谁将以下内容的XML文件读入Xdocument_Xml_Linq To Xml_Activex Documents - Fatal编程技术网

谁将以下内容的XML文件读入Xdocument

谁将以下内容的XML文件读入Xdocument,xml,linq-to-xml,activex-documents,Xml,Linq To Xml,Activex Documents,如何将以下内容从XML文件读入XDocument。 结果XDocument无论如何都不应包含“ ( A. + B ) 2. (a+b)^2 如果要从文件中读取,请执行以下操作: XDocument doc = XDocument.Load("yourfilepath"); 如果来自字符串: XDocument doc = XDocument.Parse("<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE math:ma

如何将以下内容从XML文件读入XDocument。 结果XDocument无论如何都不应包含


(
A.
+
B
)
2.
(a+b)^2

如果要从文件中读取,请执行以下操作:

XDocument doc = XDocument.Load("yourfilepath");
如果来自字符串:

XDocument doc = XDocument.Parse("<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE math:math PUBLIC "-//OpenOffice.org//DTD Modified W3C MathML 1.01//EN" "math.dtd">
    <math:math xmlns:math="http://www.w3.org/1998/Math/MathML">
        <math:semantics>
            <math:msup>
                <math:mrow>
                    <math:mo math:stretchy="false">(</math:mo>
                    <math:mrow>
                        <math:mi>a</math:mi>
                        <math:mo math:stretchy="false">+</math:mo>
                        <math:mi>b</math:mi>
                    </math:mrow>
                    <math:mo math:stretchy="false">)</math:mo>
                </math:mrow>
                <math:mn>2</math:mn>
            </math:msup>
            <math:annotation math:encoding="StarMath 5.0">(a+b)^2</math:annotation>
        </math:semantics>
    </math:math>");
XDocument doc=XDocument.Parse(“
(
A.
+
B
)
2.
(a+b)^2
");

您可以尝试调用属性上的
Remove()
方法来删除DOCTYPE信息,例如:

var xml = @"<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE math:math PUBLIC '-//OpenOffice.org//DTD Modified W3C MathML 1.01//EN' 'math.dtd'>
<math:math xmlns:math='http://www.w3.org/1998/Math/MathML'>
    <math:semantics>
        <math:msup>
            <math:mrow>
                <math:mo math:stretchy='false'>(</math:mo>
                <math:mrow>
                    <math:mi>a</math:mi>
                    <math:mo math:stretchy='false'>+</math:mo>
                    <math:mi>b</math:mi>
                </math:mrow>
                <math:mo math:stretchy='false'>)</math:mo>
            </math:mrow>
            <math:mn>2</math:mn>
        </math:msup>
        <math:annotation math:encoding='StarMath 5.0'>(a+b)^2</math:annotation>
    </math:semantics>
</math:math>";
var doc = XDocument.Parse(xml);
doc.DocumentType.Remove();
Console.WriteLine(doc.ToString());

您是否尝试过
XDocument.Parse
?它返回了什么?
var xml = @"<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE math:math PUBLIC '-//OpenOffice.org//DTD Modified W3C MathML 1.01//EN' 'math.dtd'>
<math:math xmlns:math='http://www.w3.org/1998/Math/MathML'>
    <math:semantics>
        <math:msup>
            <math:mrow>
                <math:mo math:stretchy='false'>(</math:mo>
                <math:mrow>
                    <math:mi>a</math:mi>
                    <math:mo math:stretchy='false'>+</math:mo>
                    <math:mi>b</math:mi>
                </math:mrow>
                <math:mo math:stretchy='false'>)</math:mo>
            </math:mrow>
            <math:mn>2</math:mn>
        </math:msup>
        <math:annotation math:encoding='StarMath 5.0'>(a+b)^2</math:annotation>
    </math:semantics>
</math:math>";
var doc = XDocument.Parse(xml);
doc.DocumentType.Remove();
Console.WriteLine(doc.ToString());
<math:math xmlns:math="http://www.w3.org/1998/Math/MathML">
  <math:semantics>
    <math:msup>
      <math:mrow>
        <math:mo math:stretchy="false">(</math:mo>
        <math:mrow>
          <math:mi>a</math:mi>
          <math:mo math:stretchy="false">+</math:mo>
          <math:mi>b</math:mi>
        </math:mrow>
        <math:mo math:stretchy="false">)</math:mo>
      </math:mrow>
      <math:mn>2</math:mn>
    </math:msup>
    <math:annotation math:encoding="StarMath 5.0">(a+b)^2</math:annotation>
  </math:semantics>
</math:math>