I have some xml data contained in three files (Database.xml, Participants.xml, and ConditionTokens.xml). I am trying to use external entities to place the participants and condition tokens into the database file, but when I run this code...
我有一些xml数据包含在三个文件(Database.xml,Participants.xml和ConditionTokens.xml)中。我正在尝试使用外部实体将参与者和条件标记放入数据库文件中,但是当我运行此代码时......
string xmlPath = Environment.CurrentDirectory + @"\Data\Database.xml";
XElement database = XElement.Load(xmlPath);
...there are no participants or condition tokens in my xml (the HasElements property for "database" is false). There should be two child elements. I get no errors/warnings within Visual Studio (2008), and the live schema validation seems to be happy, but something is not quite right when I run my code.
...我的xml中没有参与者或条件令牌(“数据库”的HasElements属性为false)。应该有两个子元素。我在Visual Studio(2008)中没有得到错误/警告,并且实时模式验证似乎很高兴,但是当我运行我的代码时,某些东西并不完全正确。
Could anyone tell me what I'm doing wrong?
谁能告诉我我做错了什么?
I have pasted the three xml files below.
我已粘贴下面的三个xml文件。
Thanks very much!
非常感谢!
-Dan
Database.xml
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE database [
<!ENTITY conditionTokens SYSTEM "ConditionTokens.xml">
<!ENTITY participants SYSTEM "Participants.xml">]>
<database
xmlns="experimentManager"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="experimentManager Database.xsd">
&conditionTokens;
&participants;
</database>
ConditionTokens.xml
<?xml version="1.0" encoding="utf-8" ?>
<conditionTokens>
<conditionToken>
<id>1</id>
<token>LargeToSmall</token>
</conditionToken>
<conditionToken>
<id>2</id>
<token>SmallToLarge</token>
</conditionToken>
</conditionTokens>
Participants.xml
<?xml version="1.0" encoding="utf-8" ?>
<participants>
<participant>
<id>1</id>
<conditionTokenId>1</conditionTokenId>
</participant>
<participant>
<id>2</id>
<conditionTokenId>2</conditionTokenId>
</participant>
</participants>
2 个解决方案
#1
I would have used the XmlDocument class to load the 3 documents
我会使用XmlDocument类来加载3个文档
XmlDocument xmlDatabase = new XmlDocument();
xmlDatabase.Load(databasePath);
XmlDocument xmlTokens = new XmlDocument();
xmlTokens.Load(tokensPath);
XmlDocument xmlParticipants = new XmlDocument();
xmlParticipants.Load(participantsPath);
Then using the ImportNode and AppendNode attach then to each other...
然后使用ImportNode和AppendNode相互附加...
xmlDatabase.FirstChild.AppendNode(xmlDatabase.ImportNode(xmlTokens.FirstChild), true);
xmlDatabase.FirstChild.AppendNode(xmlDatabase.ImportNode(xmlParticipants.FirstChild), true);
That should pretty much do it (or instead of using FirstChild use an xpath selector?)
应该这样做(或者使用FirstChild而不是使用xpath选择器?)
#2
I ended up using <xs:redefine>
instead.
我最终使用了
#1
I would have used the XmlDocument class to load the 3 documents
我会使用XmlDocument类来加载3个文档
XmlDocument xmlDatabase = new XmlDocument();
xmlDatabase.Load(databasePath);
XmlDocument xmlTokens = new XmlDocument();
xmlTokens.Load(tokensPath);
XmlDocument xmlParticipants = new XmlDocument();
xmlParticipants.Load(participantsPath);
Then using the ImportNode and AppendNode attach then to each other...
然后使用ImportNode和AppendNode相互附加...
xmlDatabase.FirstChild.AppendNode(xmlDatabase.ImportNode(xmlTokens.FirstChild), true);
xmlDatabase.FirstChild.AppendNode(xmlDatabase.ImportNode(xmlParticipants.FirstChild), true);
That should pretty much do it (or instead of using FirstChild use an xpath selector?)
应该这样做(或者使用FirstChild而不是使用xpath选择器?)
#2
I ended up using <xs:redefine>
instead.
我最终使用了